that's a good idea. but external server vendor doesn't support this. would there be any problems like loosing messages with iofilter approach previously suggested or should I copy and customize Mina producer component and change the messageReceiver method to send message to another endpoint when it receives the message.
from("file:///test/test/response") .convertBodyTo(String.class).threads(1) .to("custommina:tcp://localhost:6202?sync=false&textline=true"); from("vm:response") .to("log:+++ reply++++"); snippet from class ResponseHandler @Produce(uri = "vm:response") ProducerTemplate producer; @Override public void messageReceived(IoSession ioSession, Object message) throws Exception { producer.sendBody(message); Ashwin Karpe wrote: > > Hi, > > Is it not possible for you to decouple request-response communication with > your server using one way invocations and use a correlationId to correlate > the server responses at a later point i.e. > > 1> Client sends a one way invocation to the server on a port XXX and > optionally (sends a replyTo socket address in the payload) > client: > from("file:///test/test/response") > .setHeader("replyToAddress, constant("XXX"); > .to("mina:tcp://localhost:6202?sync=false"); > > 2> At a some later point the server responds to the replyToAddress with a > response that is correlated using some correlationId in the data > server: > from("mina:tcp://localhost:6202?sync=false") > .process(new Processor() { > // ... process payload and get replyToAddress > ... > // sleep fo 20 seconds > sleep(20000) > > // Send response to client > ProducerTemplate template = new ProducerTemplate(); > template.sendBody("XXX", response); > }); > > Hope this helps. > > Cheers, > > Ashwin > > anandsk wrote: >> >> it seems to work when I use iofilter, but I am not sure when this >> producer going to be destroyed, if it gets desroyed before it receives a >> reply then I will loose message, I feel that this may not be a right >> solution. >> >> from("file:///test/test/response") >> .convertBodyTo(String.class).threads(1) >> >> .to("mina:tcp://localhost:6202?sync=false&textline=true&filters=#listFilters"); >> >> from("vm:response") >> .to("log:+++ reply++++"); >> >> public class MessageFilter extends IoFilterAdapter { >> @Produce(uri = "vm:response") >> ProducerTemplate producer; >> @Override >> public void messageReceived(NextFilter nextFilter, IoSession >> session, >> Object message) throws Exception { >> if (message instanceof String) { >> producer.sendBody(message); >> } >> >> nextFilter.messageReceived(session, message); >> } >> >> } >> >> >> >> >> anandsk wrote: >>> >>> Ashwin, >>> >>> it is a simulated consumer in my code with a delay, actual consumer is a >>> external system which could take some time to send reply. >>> >>> I am using "toasync" instead of "to" so that I don't loose message. are >>> we saying that option sync=false doesn't work in combination with >>> "toasync"?. >>> >>> Thanks for working on a new framework. I am using this for a production >>> app, so I don't have much time to wait and switch to a new tcp >>> frameworks. >>> >>> Thanks, >>> Anand >>> >>> Ashwin Karpe wrote: >>>> >>>> Hi, >>>> >>>> Anand, it seems like you have sync set to true for the consumer, >>>> thereby making it a In-Out exchange driven consumer (i.e >>>> request/response). >>>> >>>> However your producer is set with sync=false thereby making it an >>>> in-only. This will cause the response to fall through the cracks and >>>> cause connection closure on the consumer. This should hopefully fix it >>>> for you. >>>> >>>> BTW, as Claus mentioned, I am working on a Camel Netty component >>>> (coding is done, currently writing tests and adding SSL support). I >>>> will bring it to the community in the next 2-3 weeks after due testing >>>> and cleanup. >>>> >>>> Cheers, >>>> >>>> Ashwin... >>>> >>>> >>>> anandsk wrote: >>>>> >>>>> Hi, Thanks for the response. I can use only one thread for sending >>>>> messages becuase I can have only one TCP connection to external >>>>> server. if I change sync flag to true then that thread is going to >>>>> wait till the response comes back before it sends another message >>>>> right?. I want to be able to send multiple requests one after the >>>>> other without waiting for a response. responses need to be processed >>>>> asynchronously.So, I can't set sync flag to true, is there any other >>>>> solution to my problem. >>>>> >>>>> Thanks, >>>>> Anand >>>>> >>>>> willem.jiang wrote: >>>>>> >>>>>> Hi I think you need to change the route like this >>>>>> >>>>>> from("mina:tcp://localhost:6202?textline=true&sync=true").process(new >>>>>> Processor() { >>>>>> public void process(Exchange exchange) throws Exception { >>>>>> String body = exchange.getIn().getBody(String.class); >>>>>> Thread.sleep(30000); >>>>>> exchange.getOut().setBody("Bye 1" + body); >>>>>> } >>>>>> }); >>>>>> >>>>>> from("file:///test/test/response") >>>>>> .convertBodyTo(String.class) >>>>>> .toAsync("mina:tcp://localhost:6202?sync=true&textline=true",10) >>>>>> .to("log:+++ reply++++"); >>>>>> To make sure the mina client can get the right response. >>>>>> >>>>>> Willem >>>>>> >>>>>> anandsk wrote: >>>>>>> Thanks. yes, I have seen the examples and I modified my code. but it >>>>>>> still >>>>>>> doesn't deliver reply asyncronously. >>>>>>> I am thinking may be camel Mina's sync option may be conflicting >>>>>>> with async >>>>>>> route. Please see my code below. >>>>>>> >>>>>>> >>>>>>> from("mina:tcp://localhost:6202?textline=true&sync=true").process(new >>>>>>> Processor() { >>>>>>> public void process(Exchange exchange) throws >>>>>>> Exception { >>>>>>> String body = >>>>>>> exchange.getIn().getBody(String.class); >>>>>>> Thread.sleep(30000); >>>>>>> exchange.getOut().setBody("Bye 1" + body); >>>>>>> } >>>>>>> }); >>>>>>> >>>>>>> from("file:///test/test/response") >>>>>>> .convertBodyTo(String.class) >>>>>>> >>>>>>> .toAsync("mina:tcp://localhost:6202?sync=false&textline=true",10) >>>>>>> .to("log:+++ reply++++"); >>>>>>> >>>>>>> >>>>>>> >>>>>>> Claus Ibsen-2 wrote: >>>>>>>> Have you seen the 2 asyncTo examples which are listed here? >>>>>>>> http://camel.apache.org/examples.html >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Tue, Mar 2, 2010 at 5:10 PM, anandsk <sku...@arccorp.com> wrote: >>>>>>>>> Hi, >>>>>>>>> I tried this route with camel 2.2 and it is not forwarding >>>>>>>>> response to >>>>>>>>> end >>>>>>>>> point defined in async "direct:response". also I see the logs >>>>>>>>> showing >>>>>>>>> that >>>>>>>>> mina producer receiving the message back from tcp server but it is >>>>>>>>> not >>>>>>>>> forwarding them to async endpoint. am I doing this wrong. >>>>>>>>> >>>>>>>>> Thanks, >>>>>>>>> Anand >>>>>>>>> >>>>>>>>> >>>>>>>>> from("mina:tcp://localhost:6202?textline=true&sync=true").process(new >>>>>>>>> Processor() { >>>>>>>>> public void process(Exchange exchange) throws >>>>>>>>> Exception { >>>>>>>>> String body = >>>>>>>>> exchange.getIn().getBody(String.class); >>>>>>>>> //Thread.currentThread(); >>>>>>>>> Thread.sleep(1000); >>>>>>>>> exchange.getOut().setBody("Bye 1" + >>>>>>>>> body+"\n"); >>>>>>>>> //exchange.getOut().setBody("Bye 2" + >>>>>>>>> body+"\n"); >>>>>>>>> } >>>>>>>>> }); >>>>>>>>> >>>>>>>>> >>>>>>>>> //from("jms:test.Camel1") >>>>>>>>> from("file:///test/test/response") >>>>>>>>> .convertBodyTo(String.class).threads(1) >>>>>>>>> //.to("log:jms.queue.message") >>>>>>>>> //.bean(smooks.StatusRequestMessageHandler.class) >>>>>>>>> //.setHeader(MinaEndpoint.HEADER_MINA_IOSESSION, >>>>>>>>> expression) >>>>>>>>> >>>>>>>>> .to("mina:tcp://localhost:6202?textline=true&sync=true") >>>>>>>>> .toAsync("direct:response",1) >>>>>>>>> .to("log:direct"); >>>>>>>>> >>>>>>>>> from("direct:response") >>>>>>>>> .to("log:jms.queue.message"); >>>>>>>>> -- >>>>>>>>> View this message in context: >>>>>>>>> http://old.nabble.com/Mina-async-route-not-working-tp27757690p27757690.html >>>>>>>>> Sent from the Camel - Users mailing list archive at Nabble.com. >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> Claus Ibsen >>>>>>>> Apache Camel Committer >>>>>>>> >>>>>>>> Author of Camel in Action: http://www.manning.com/ibsen/ >>>>>>>> Open Source Integration: http://fusesource.com >>>>>>>> Blog: http://davsclaus.blogspot.com/ >>>>>>>> Twitter: http://twitter.com/davsclaus >>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>> >>>> >>> >>> >> >> > > -- View this message in context: http://old.nabble.com/Mina-async-route-not-working-tp27757690p28191049.html Sent from the Camel - Users mailing list archive at Nabble.com.