Hi!

The question is how can I asynchronously submit data received by Jetty
component to the JMS queue?

The use-case:

1) Client submits data using the POST to the specific URL
2) The message is received by the application and submitted to the JMS queue
3) Empty response is sent to the client (HTTP code is 200, meaning
everything is OK, message was received for later processing).
...
4) Message is extracted from the queue and processed by some logic.

I’ve tried this variant:

<route>
  <from uri="jetty:http://localhost:8080/greeter"/>
  <to uri="activemq:queue:GREET" />
</route>

but it works synchronously, the response is not sent to the client (who
sends the POST) until the message is processed. The reason is that Jetty
component generates HttpExchange that always has exchange pattern InOut,
therefore JmsProducer, created by the JmsComponent waits for the reply.

I found the following workaround:

<route>
 <from uri="jetty:http://localhost:8080/greeter"/>
 <to uri="bean:async?method=send" />
</route>

there async bean is instance of:

public class AsyncBean {
    @EndpointInject(uri = "activemq:GREET")
    ProducerTemplate<Exchange> producer;
    public String doSomething(String msg) {
        producer.sendBody(msg);
        return ""; // Send empty HTTP response to the client
    }
}

but I don’t like this solution too much, because I need one bean for
each HTTP->JMS queue case (because of endpoint hard-coded in the
annotation). Is there cleaner way to do this? Ideally, I want everything
specified in the camel-context.xml only.

-- 
WBR,
Ivan S. Dubrov


Reply via email to