You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jonv <jo...@generaldynamics.uk.com> on 2011/11/25 09:34:37 UTC

Single request with multiple replies over TCP

Hello all,

Im new to camel and currently doing an evaluation exercise!

What Im trying to achieve is to place camel in the middle of two apps.
The apps use XML over TCP to communicate over one connection. The message
pattern is kinda pub/sub or single request with multiple replies.

The msgs flows are....

             ----REG---->               ----REG--->
CLIENT   <--ACK------   CAMEL   <--ACK-----   SERVER
            <--MSG1----                <--MSG1---
            <--MSG2----                <--MSG2---
                                              <--etc-----

Ive implemented an XML codec which I belive works ok. However using the
following...

<camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
  <route>
    <from
uri="mina:tcp://localhost:17171?sync=true&amp;disconnectOnNoReply=false&amp;allowDefaultCodec=false&amp;codec=#ptCodec"/>
    <to
uri="mina:tcp://localhost:9998?sync=true&amp;allowDefaultCodec=false&amp;disconnectOnNoReply=false&amp;codec=#ptCodec"/>
  </route>
</camelContext>

.... only allows the ACK to be received by the client (no msgs). The
additional msgs are received by the 'encoder' of the <to> codec but not
passed on. Im assuming that the session correlates one response for each
request.

How can camel be used for this pattern? 

Any help will be appreciated.

Cheers

Jon.

--
View this message in context: http://camel.465427.n5.nabble.com/Single-request-with-multiple-replies-over-TCP-tp5022206p5022206.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Single request with multiple replies over TCP

Posted by jonv <jo...@generaldynamics.uk.com>.
If you cant wait for the new mina component you will have to write your own
camel component to do this - at least that is what I ended up doing!
Im new to camel so what I did cannot have the best implementation strategy,
so I will probably replace with the mentioned mina2 component. However a
brief explanation of what I did is below that may be of some help to you:

An example config is below:

<camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
    <route id="Client2Server">
      <from
uri="myTCPComp://localhost:11111?respEp=respPathOut&amp;bufferSize=8192"/>
      <log message="Msg from Client to
Server................................" />
      <to
uri="myTCPComp://localhost:22222?respEp=vm:respPathIn&amp;bufferSize=8192"/>
    </route>

    <route id="Server2Client">
      <from uri="vm:respPathIn"/>
      <log message="Msg from Server to Client
................................" />
      <to uri="vm:respPathOut"/>
    </route>
  </camelContext>

The 'myTCPComp' consumer creates a TCP Server on localhost:11111. This also
creates another consumer for the responses - here respPathOut. Any messages
received by vm:respPathOut is returned to the TCP client.
The 'myTCPComp' producer creates a TCP client connecting on localhost:22222.
Any responses will be written to vm:respPathIn.

Also if no manipulation is required for the return messages, and I dont set
the respEp parameter on the uri my code uses a default endpoint for the
responses (so the endpoint vm:default is created by the camel consumer and
messages sent to it from the camel producer. Giving just...

<camelContext xmlns="http://camel.apache.org/schema/spring" trace="false">
    <route id="Client2Server">
      <from uri="myTCPComp://localhost:11111"/>
      <log message="Msg from Client to
Server................................" />
      <to uri="myTCPComp://localhost:22222"/>
    </route>
</camelContext>

Which will do the same as the first example without the response log message
being written.



--
View this message in context: http://camel.465427.n5.nabble.com/Single-request-with-multiple-replies-over-TCP-tp5022206p5157169.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Single request with multiple replies over TCP

Posted by Chad Beaulac <ca...@gmail.com>.
You will only get one reply if you're using the camel-mina component. The camel-mina2 component will handle multiple replies. It is not complete yet. 

Regards,
Chad 

Sent from my iPhone

On Jan 18, 2012, at 3:39 PM, mgiammarco <mg...@gmail.com> wrote:

> I have the same problem. I send a message and I expect several ASYNC replies.
> Unfortunately I get only ONE reply using either an activemq client with
> camel and a java stomp client.
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Single-request-with-multiple-replies-over-TCP-tp5022206p5155849.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Single request with multiple replies over TCP

Posted by mgiammarco <mg...@gmail.com>.
I have the same problem. I send a message and I expect several ASYNC replies.
Unfortunately I get only ONE reply using either an activemq client with
camel and a java stomp client.

--
View this message in context: http://camel.465427.n5.nabble.com/Single-request-with-multiple-replies-over-TCP-tp5022206p5155849.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Single request with multiple replies over TCP

Posted by jonv <jo...@generaldynamics.uk.com>.
Thanks Ioannis however the 'responses' are never ending. Which is why I
mentioned its like pub/sub.

The two applications I have use an 'always open' TCP connection where the in
and out messages streams are effectively 'sessionless'. E.g.

TCP Client opens connection with TCP Sever Listener .
Client sends  a message to Srv.
Srv continually sends messages to cli over the same connection.
(Plus there may be the possiblity that the client sends further messages in
the future).

So a gathering strategy will not work here!

What I require is the request and response channels to work independently.

DO you think camel can support this?

--
View this message in context: http://camel.465427.n5.nabble.com/Single-request-with-multiple-replies-over-TCP-tp5022206p5022909.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Single request with multiple replies over TCP

Posted by Ioannis Canellos <io...@gmail.com>.
If you are expecting one message for each response, then I guess that you
can get this message back by having the sync option set to true.
However, I think that you mentioned multiple responses per request. I think
that you could easily solve this one by implementing the appropriate
filter, that would gather all the responses and group them into a single
message before returning it to the io handler.

-- 
*Ioannis Canellos*
*
FuseSource <http://fusesource.com>

**
Blog: http://iocanel.blogspot.com
**
Apache Karaf <http://karaf.apache.org/> Committer & PMC
Apache Camel <http://camel.apache.org/> Committer
Apache ServiceMix <http://servicemix.apache.org/>  Committer
Apache Gora <http://incubator.apache.org/gora/> Committer
Apache DirectMemory <http://incubator.apache.org/directmemory/> Committer
*