Produce messages to IBM MQ using REST API. Apache Camel - apache-camel

I have to send messages to IBM MQ by hitting a rest service. Below is the code I came up with, using Camel XML DSL.
<rest path="/basePath">
<post uri="/path" consumes="application/xml" produces="application/xml">
<to uri="ibmmq:QUEUE.NAME"/>
</post>
</rest>
When I try to post the message, I get the following exception
org.apache.camel.RuntimeExchangeException: Failed to resolve replyTo destination on the exchange
Is the post method expecting response back from QUEUE, so that it can respond back to rest client?
I only need the post service to reply with 200, if the message is successfully produced to QUEUE, 500 otherwise.
How to solve this problem?

Pattern of your exchange is InOut so this is default behavior for your jms producer. Try change it for specific endpoint like this:
<to uri="ibmmq:QUEUE.NAME" pattern="InOnly"/>

Related

Camel-netty4: how to wait response before send next request

I have created route that accept request from multiple producers and send to a remote server by using netty4 with request-response. However, when camel is sending a request to remote server and waiting for response, next incoming request is received and want to send to remote server but got IOException as camel cannot receive response.
So, how to set Camel-Netty4 send request and wait for response before send next.
The route configuration:
from("direct:DirectProcessOut?block=true")
.to("netty4:tcp://192.168.1.2:8000?sync=true&synchronous=true&reuseChannel=true")
I actually ran into a similar issue trying to send out several messages at a time based on rows in a database table. The calls wouldn't wait for each other to complete and essentially stepped on each other and either hung or blew up.
The solution I eventually found was to use a message queue. Take in your requests and route them into a single activemq route.
So something like:
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="direct:direct:DirectProcessOut"/>
<to uri="activemq://processOutQueue"/>
</route>
</camelContext>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="activemq://processOutQueue"/>
<to uri="netty4:tcp://192.168.1.2:8000?sync=true&synchronous=true&reuseChannel=true"/>
</route>
</camelContext>
My case was a little different, so I'm not sure if this will preserve your message you want to send. But hopefully it gives you a place to start.

Camel jms request/reply threading model

I am using camel jms in a synchronous way using request-reply pattern.The camel route exposes a cxf endpoint and it places the message in to the jms queue another component process it and sends the response in replyto queue.
A new thread is getting created while receiving the reply from replyto queue?Iam facing issues with using log4j MDC with in the camel route.The values store in MDC are no more available?
Is it the behaviour of camel jms request/reply pattern?
Below is the JMS endpoint:
<to id="QueueEndpoint" pattern="InOut" uri="hornetq:queue:{{esb.api.requestqueue}}?replyTo=queue:{{esb.api.responsequeue}}&useMessageIDAsCorrelationID=true&replyToType=Exclusive&requestTimeout={{esb.api.queue.requesttimeout}}"/>

Apache CXF - How to know while sending which response "Broken pipe" is occuring

I see lots of exceptions[ClientAbortException: java.net.SocketException: Broken pipe] in
my catalina log while trying to send the response back but i am not able to tie this exception
to a particular request with a particular Inbound Message ID, Is there any way by which i can know, while sending
which response this exception is occuring in cxf ?
Try enabling SOAP logging. If you enable SOAP logging as follows, you will see SOAP requests and/or responses including HTTP headers. CXF also assigns a message ID for each request/response.
#WebService
#org.apache.cxf.annotations.Logging
public interface AssetServices {
....
}

Camel CXFRS response

camel-fuse 2.8
I have a camel jaxrs server which accepts requests then kicks-off 2 Camel routes.
The first route, consumes requests from cxfrs endpoint/bean and ships them to jms queue inbox.
The second route, consumes requests from jms queue inbox for business logic processing, then ships the results to jms queue outbox.
My question is related to http response and sending the results to jaxrs server consumer.
Is it possible to send an http response back to http client from first route with results from second route? (synchronously)
from("cxfrs:bean:personLookupEndpoint") <-- http client waits for response...
.setExchangePattern(ExchangePattern.InOut)
.process(new RequestProcessor())
.to(inbox);
from(inbox)
.unmarshal(jaxb)
.process(new QueryServiceProcessor())
.to("bean:lookupService?method=processQuery(${body})")
.convertBodyTo(String.class)
.to(outbox); <-- need to send results to font-end consumer synchronously ...
Do you really need to do it using queues? I think that it would be better to use direct: routes instead.
There is a possibility to use the InOut exchange pattern for a JMS endpoint, but it has some limitations: http://fusesource.com/docs/router/2.2/transactions/JMS-Synchronous.html

Camel CXF consumer, webservice method has no response

I'm trying to consume a webservice from camel using the cxf component, like this:
<cxf:cxfEndpoint id="webservice"
address="http://webservice.url.com/webservice"
serviceClass="com.url.webservice.MyWebService"/>
<camel:camelContext>
<camel:route>
<camel:from uri="direct:a"/>
<camel:inOnly uri="cxf:bean:webservice?defaultOperationName=sendMessage"/>
</camel:route>
</camel:camelContext>
The sendMessage method has no response, hence the inOnly rather than to (although I have the same problem when I try to instead). The problem is that apparently camel still expects a response, and the route hangs while waiting for one. I suppose if I let it try long enough, it would eventually time out.
To be clear, I'm running a test method:
/* ... */
#Produce(uri = "direct:a")
protected ProducerTemplate directA;
#Test
public void sendMessage() throws Exception {
directA.sendBody(new String[] {"client id", "message"});
directB.sendBody(new String[] {"client id", "message 2"});
}
And I'm seeing the effect of the first call (that is, the message arrives at the server), but not the second, and the method doesn't finish running (again, I'm assuming it'll timeout at some point... if so, the timeout's pretty long: I ran the test as I started writing this, and it's still running).
Am I missing something? Is it a bug? Is it just bad practice to have webservice methods with no response?
By the way, when testing methods which have a response, it works fine.
I think Willem Jiang recently fixed some issue with one-way CXF in Camel recently. Maybe try Camel 2.6-SNAPSHOT from trunk.
I personally prefer two-way with web services, just returning some ACK back in case there is no data to return back. The client most often want some confirmation the server has received and acknowledged the data.
camel-cxf producer decides if it will handle the response message by checking if the operation is oneway. Even the sendMessage operation is oneway invocation, your server should send Http states 202 message to the client according the HTTP protocol, otherwise camel-cxf producer will still wait for the response.
BTW, I think the issue[1] that Claus said was related to async invocation of camel-cxf producer with one way message, not sure if it's the same issue as you mentioned(I didn't know which version of camel are you using).
[1]https://issues.apache.org/jira/browse/CAMEL-3426
Willem

Resources