camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: How to act as TCP-client with Camel + Mina/Netty?
Date Thu, 06 Sep 2012 09:27:16 GMT

There is a number of JIRA tickets about this. Currently its not
supported in the Camel components.
eg to let Camel act as a client listening on a remote TCP server.

On Wed, Sep 5, 2012 at 2:50 PM, Urppa <> wrote:
> I'm working on my first Camel-based integration project and have a question
> about integrating to an existing TCP-server (for which I don't have a source
> code so no changes can be done to it) with either Mina or Netty (not sure
> which is the better one to use for this). I've read the Camel in Action-book
> but didn't find the answer there for this particular scenario.
> The scenario is as follows:
> - There is a legacy server application X that exposes a TCP server-port
> 9999.
> - The application X is to be used so that a TCP-client opens a connection to
> port 9999, sends one string "CONNECT"+CRLF and nothing else and then starts
> listening the incoming stream from the server.
> - Application X will periodically (time varies randomly, from seconds to
> hours) send a string to the TCP-client and the TCP-client should then do
> something with it, in my case it should be forwarded to a JMS-queue as a
> TextMessage.
> - The TCP-client should keep the connection open indefinitely and it
> connection is lost, automatically retry the connection until it succeeds and
> then continue processing like above.
> I have been able to partly implement this with Camel with Mina BUT ONLY so
> that Mina exposes a TCP-server that can be contacted with my simple
> test-client. I am able to send strings from the test client and have them
> forwarded as JMS-messages so the routing part seems to work as long as I
> just get something into the TCP-server endpoint.
> But here is my problem How do I get the TCP-endpoint to act as TCP-client
> instead of TCP-server, i.e. connect to the TCP-server port 9999, send the
> CONNECT-string once and then just keep the connection open and process the
> incoming strings from the TCP-server?!?
> I can't use polling to contact the server because it doesn't store anything
> for later retrieval, it will only send data to connected TCP-clients if they
> are connect at the moment when it has data to send, it is a kind of
> "sensor"-type of application with no message/data buffering. Furthermore,
> the system is very time-sensitive, I must process the text message
> immediately after the server sends it, say, within 100-200ms, definitely
> under 1s.
> So, first of all: Is this possible with existing components, either Mina or
> Netty? Which one? How would I define the endpoint? Or do I need to write my
> own component? I've done some TCP-socket programming with Java so that would
> be doable, but I'd like to avoid that if possible and just use the existing
> stuff provided with Camel, otherwise; what's the point of using it. But
> obviously I'll try the custom-component way if I have to.
> So optimally I'd like the system to act something like this:
> - When I start the CamelContext, a TCP-client endpoint will actively try to
> connect to the TCP-server on port 9999 and if it fails, it will try again
> periodically, say, once every 10 seconds. And also if the connection is
> lost, it would retry to connect again automatically. The reason being that
> the server may be unreachable at times so the TCP-client endpoint should be
> robust enough to retry to connect if the connection is lost or server app
> not reached immediately.
> - After connection is formed, the TCP-client endpoint should keep the
> connection open, listen to the inbound server-stream and when it receives a
> line of text from the server, just forward it to the JMS-queue as
> textmessage,the received string being the body.
> Any advice on implementing this? It doesn't feel to me that complex
> scenario, only the TCP-client/server roles seem a bit problematic.
> --
> View this message in context:
> Sent from the Camel - Users mailing list archive at

Claus Ibsen
Twitter: davsclaus, fusenews
Author of Camel in Action:

View raw message