1

I have RouteBuilder as below.

from("seda:requestQueue").routeId("service_request").log(LoggingLevel.INFO, "Processing STARTED,  {body = ${body}")
            .setBody(body())
            .to("select * from SERVICE_REQUEST WHERE requestType=:#TYPE AND requestDate=:#date AND owner=:#OWNER)
            .split(body()).streaming().process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    Map<String, Object> row = exchange.getIn().getBody(Map.class);
                    if (row == null) {
                        LOGGER.info("Request is new. No records found.");
                        return;
                    }
                    //Duplicate request. Q(Not sure how to terminate the process with exception)
                }
            })
            .log(LoggingLevel.INFO, "Processing CONTINUE,  {body = ${body}")
            .setBody(body())
            .to("insert into SERVICE_REQUEST (ID,....) ").log(LoggingLevel.INFO, "Processing COMPLETED").end();

I would like to achieve

  1. Whenever request is submitted (for now via SEDA), first check whether the same request has been available in database or not.
  2. If it is not available then only insert into database (new row)

Question: 1. How can I set original request body to insertQuery? As per the above code, body received at seda:requestQueue is not available to to("insert into SERVICE..).

Namphibian
  • 12,046
  • 7
  • 46
  • 76
harshit2811
  • 827
  • 1
  • 7
  • 21

1 Answers1

0

Your splitter will send out messages with a new body (based on the SQL). So, the body itself cannot be used.

Instead, before calling the splitter, set the body to a property of the Exchange. Then, when you need to use it, read the value of the property.

.setProperty("mySampleProperty", simple("${body}")

If you need it back as the body, then -- at that point -- set the body to the value that you previously stored in the Exchange property.

Here's a similar question: Apache Camel: how store variable for later use

Darius X.
  • 2,886
  • 4
  • 24
  • 51