Spring boot
Apache Camel middleware provides you a messaging technology which makes use of routing and mediation rules. Two endpoints are required for apache camel PRODUCER & CONSUMER. From endpoint here refer 2 different URLs. Domain-specific language(DSL’S) is required for routing.
ATTRIBUTES REQUIRED -
1) route.from
2) route.to
To use it with SPRING BOOT we make use of CAMEL CONTEXT
public class NewOrderRoute extends RouteBuilder {
@Autowired
CamelContext context;
@Override
public void configure() throws Exception {
context.setStreamCaching(true);
log.info("streamCaching {}", context.isStreamCaching());
from("scheduler://getEZRNewOrders?initialDelay=600&delay=600000")
.process(new EZRHeaderDetailsProcess())
.log("Header ${body}").setHeader(Exchange.HTTP_METHOD, constant("POST"))
.setHeader(Exchange.CONTENT_TYPE, constant("application/x-www-form-urlencoded"))
.to(EZRConfig.GET_NEW_ORDER_URL)
.log("Received body ${body}").unmarshal(ezrJsonFormat)
.process(new OMSNewOrderProcess()).marshal(omsJsonFormat)
.to("file:/home/ritvik/Desktop/a");
}
}
Here from(String uri) is used to initiate the messaging process for building ROUTE
DEFINITION
For example
-from("scheduler://getEZRNewOrders?initialDelay=600&delay=600000") in above code
process(Processor processor) is used to define the process for route defination .
public class EZRReturnOrderHeaderProcess implements Processor {
private DateTimeFormatter format1 = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
private DateTimeFormatter format2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(generateReturnOrderHeader());
}
private Object generateReturnOrderHeader() {
String timeStamp = LocalDateTime.now().format(format1);
StringBuilder inputValues = new StringBuilder();
inputValues.append("AppId=" + EZRConfig.APP_ID);
inputValues.append("&Timestamp=" + timeStamp);
inputValues.append("&Token=" + EZRConfig.TOKEN);
String value = inputValues.toString();
return "AppId=" + EZRConfig.APP_ID + "&Timestamp=" + timeStamp + "&Sign=" + SignUtil.generateSHA1(value) + "&AppSystem=" + EZRConfig.APP_SYSTEM+
"&Args={\"ReturnTimeStart\": " + LocalDateTime.now().minusDays(5).format(format2) + ",\n" +
"\"ReturnTimeEnd\": " + LocalDateTime.now().format(format2) + ",\n" +
"\"PageIndex\": \"1\"}";
}
}
to() is use to define the consumer of the route definition.
JacksonDataFormat ezrJsonFormat = new JacksonDataFormat(EZRResultSetDto.class);
ezrJsonFormat.setPrettyPrint(true);
JacksonDataFormat omsJsonFormat = new JacksonDataFormat(OMSOrderDto.class);
omsJsonFormat.setPrettyPrint(true);
Further the marshalling and unmarshalling of data is also required to convert data from one form to another like JSON to JAVA Object .
MARSHALLING/UNMARHSALLING – Converting from original data to byte form and vice versa.
Following dependency is required for apache camel in spring boot project .
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-servlet-starter</artifactId>
<version>3.0.1</version>
</dependency>
You can make use of folliwng alternative messaging technology-
We are a ERP Development Company that enables enterprises to streamline operations and drive returns, using next-gen technologies, with our development services. Our services include developing applications for all your ERP needs from CRM, WFM, and HRM to eCommerce, accounting, and wealth management software. We use an extensive tech stack including Javascript, Springboot, JUnit to develop end to end customized software for your enterprise. Get in touch with our experts to know more about how you can implement these technologies into your business.