mercredi 13 février 2019

Question on OOAD/Application Design/Structure

I am building a standalone Spring Boot application which uses Camel. The application is working fine, but i want to know how can i improve application design like organizing classes and methods so that i can be clean and scalable.

Below are the three main classes in my application and others are supporting classes.

Can you suggest the scope of improvement in this structure ?

Please let me know if you need more input on other classes or properties file or constant classes which i have been using.

TradeServiceApplication.java

@SpringBootApplication
public class TradeServiceApplication {

    public static void main(String[] args) {
        new SpringApplicationBuilder(TradeServiceApplication.class).web(WebApplicationType.NONE).run(args);
    }

}

CamelConfiguration.java

@Configuration
public class CamelConfiguration {

    @Autowired
    CamelContext camelContext;

    @Autowired
    TsRoute tsRoute;

    @Bean
    CamelContextConfiguration contextConfiguration() {

        return new CamelContextConfiguration() {
            @Override
            public void beforeApplicationStart(CamelContext camelContext) {
                try {
                    camelContext.addRoutes(tsRoute);
                } catch (Exception e) {
                    System.out.println("Exception occured while creating Camel Context.");
                    e.printStackTrace();
                }
            }

            @Override
            public void afterApplicationStart(CamelContext camelContext) {
                try {
                    camelContext.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
    }
}

TsRoute.java

@Component
public class TsRoute extends RouteBuilder {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Value("${camel.ts.cron}")
    private String cron;

    @Value("${camel.ts.timezone}")
    private String timezone;

    @Value("${camel.ts.auditDir}")
    private String auditDir;

    @Value("${camel.ts.queue.out}")
    private String outQueue;

    private static final DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy-HHmmSS");

    /**
     * Route configuration
     * 1. Call tradeService.searchTransaction(Date) every 5 minutes.
     * 2. Create TS Service XML(TS Service Generic Internal Format)
     * 3. Log to file system for Auditing
     * 3. Validate TS Service Internal XML Using XML Schema. (Optional - External Configuration)
     * 4. Transform TS Service Internal XML to C-XML
     * 5. Validate C-XML using C-XML Schema
     * 6. Send to Outgoing MQ.
     */

    @Override
    public void configure() throws Exception {
        logger.info("TsRoute.configure()");

        from("quartz2://tsTimer?cron=" + cron.replaceAll(" ", "+") + "&trigger.timeZone=" + timezone + "&stateful=true")
        .bean(TradeService.class)
        .process(new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                exchange.setProperty("inFileName","in-"  + dateFormat.format(new Date()) + ".xml");
                exchange.setProperty("outFileName","out-"  + dateFormat.format(new Date()) + ".xml");
            }
        })
        .marshal().jacksonxml(true)
        .wireTap("file:" + auditDir + "/?fileName=${header.inFileName}")
        .to("xslt:trans.xslt")
        .to(outQueue)
        .to("file:" + auditDir + "/?fileName=${header.outFileName}")
        .to("log:org.ts.tradeservice.camel?level=INFO&showBody=true")
        .end();
    }

}

Aucun commentaire:

Enregistrer un commentaire