You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Urppa <pe...@insta.fi> on 2012/09/05 14:50:05 UTC

How to act as TCP-client with Camel + Mina/Netty?

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: http://camel.465427.n5.nabble.com/How-to-act-as-TCP-client-with-Camel-Mina-Netty-tp5718671.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to act as TCP-client with Camel + Mina/Netty?

Posted by "Morgan.Hautman" <mo...@gmail.com>.
Hello,

Is there any update on this?
I may be considering contributing if it's isn't.

Morgan



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-act-as-TCP-client-with-Camel-Mina-Netty-tp5718671p5758101.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to act as TCP-client with Camel + Mina/Netty?

Posted by Claus Ibsen <cl...@gmail.com>.
No

We love contributions so people can work on this if they want / need
this functionality out of the box.
http://camel.apache.org/contributing.html

On Wed, Sep 25, 2013 at 8:43 PM, vjboston <vj...@gmail.com> wrote:
> Hi Claus,
> Do you know when this is going to be implemented ?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-act-as-TCP-client-with-Camel-Mina-Netty-tp5718671p5740215.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: How to act as TCP-client with Camel + Mina/Netty?

Posted by vjboston <vj...@gmail.com>.
Hi Claus,
Do you know when this is going to be implemented ? 



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-act-as-TCP-client-with-Camel-Mina-Netty-tp5718671p5740215.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to act as TCP-client with Camel + Mina/Netty?

Posted by Claus Ibsen <cl...@gmail.com>.
Yes not implemented yet.

On Wed, Aug 28, 2013 at 10:35 AM, siddharthrajjain
<si...@yahoo.com> wrote:
> is this limitation still there?
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-act-as-TCP-client-with-Camel-Mina-Netty-tp5718671p5738130.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: How to act as TCP-client with Camel + Mina/Netty?

Posted by siddharthrajjain <si...@yahoo.com>.
is this limitation still there?



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-act-as-TCP-client-with-Camel-Mina-Netty-tp5718671p5738130.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to act as TCP-client with Camel + Mina/Netty?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

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 <pe...@insta.fi> 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: http://camel.465427.n5.nabble.com/How-to-act-as-TCP-client-with-Camel-Mina-Netty-tp5718671.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

RE: How to act as TCP-client with Camel + Mina/Netty?

Posted by Urppa <pe...@insta.fi>.
Well, I did implement my own custom endpoint with Mina. camel-mina or camel-netty didn't have the capability to act as TCP-client so I had to do it myself.

From: Jean-Baptiste Onofré [via Camel] [mailto:ml-node+s465427n5758111h24@n5.nabble.com]
Sent: 27. lokakuuta 2014 18:26
To: Riipinen Petri
Subject: Re: How to act as TCP-client with Camel + Mina/Netty?

Why not just using camel-mina or camel-netty ?

I didn't read the original message. So I will get back to you with more details in a couple of days.

Regards
JB


Sent from my Samsung Galaxy smartphone.


-------- Original message --------
From: "Morgan.Hautman" <[hidden email]</user/SendEmail.jtp?type=node&node=5758111&i=0>>
Date:27/10/2014  15:57  (GMT+01:00)
To: [hidden email]</user/SendEmail.jtp?type=node&node=5758111&i=1>
Cc:
Subject: Re: How to act as TCP-client with Camel + Mina/Netty?

Hello,

Is there any update on this?
I may be considering contributing if it's isn't.

Morgan



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-act-as-TCP-client-with-Camel-Mina-Netty-tp5718671p5758101.html
Sent from the Camel - Users mailing list archive at Nabble.com.

________________________________
If you reply to this email, your message will be added to the discussion below:
http://camel.465427.n5.nabble.com/How-to-act-as-TCP-client-with-Camel-Mina-Netty-tp5718671p5758111.html
To unsubscribe from How to act as TCP-client with Camel + Mina/Netty?, click here<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5718671&code=cGV0cmkucmlpcGluZW5AaW5zdGEuZml8NTcxODY3MXw1OTU2OTkzMzg=>.
NAML<http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>




--
View this message in context: http://camel.465427.n5.nabble.com/How-to-act-as-TCP-client-with-Camel-Mina-Netty-tp5718671p5758216.html
Sent from the Camel - Users mailing list archive at Nabble.com.