Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D0CABD5E2 for ; Thu, 6 Sep 2012 09:28:04 +0000 (UTC) Received: (qmail 54684 invoked by uid 500); 6 Sep 2012 09:28:03 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 54635 invoked by uid 500); 6 Sep 2012 09:28:03 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 54596 invoked by uid 99); 6 Sep 2012 09:28:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Sep 2012 09:28:02 +0000 X-ASF-Spam-Status: No, hits=0.6 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of claus.ibsen@gmail.com designates 209.85.217.173 as permitted sender) Received: from [209.85.217.173] (HELO mail-lb0-f173.google.com) (209.85.217.173) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Sep 2012 09:27:56 +0000 Received: by lbbgm13 with SMTP id gm13so1207139lbb.32 for ; Thu, 06 Sep 2012 02:27:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=NIq8ftyErT8Xmc+5gPM8JVEVg8x1vohT31+23lY0WHM=; b=RrQEP/m5gWTMUzNYHwi4wKbmiIGgAnO/lOtGhyXTKeLWcRqcEcLEwVFHsgsGqxHVe8 TQaYbw3rVdhe0kh7mrg338z06cpkxiC8V5GMFV4LLpGw3g4Gm5BBO6qSmi0iERxZ+5RV Huaz3cynj6hDoO3uDHEr4xugQ1eSfeton1lLrNMiiLxpzoxaY2THaUn2fQCHtkQjCxVC UuvJvtDmx0mPpOEanmsUF+5+s8OO1nWbQvmtdF4dyHXmoDDhb9wdwbgSkzQZj/mGiZsI HvNZevVwAvJGDLUtgx9EdVyaHLY02Sbb8sFPuR3xApl+HsYc+DS7GgeBM+1f6n92baGx 1EJA== Received: by 10.152.108.144 with SMTP id hk16mr1363388lab.2.1346923656321; Thu, 06 Sep 2012 02:27:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.7.230 with HTTP; Thu, 6 Sep 2012 02:27:16 -0700 (PDT) In-Reply-To: <1346849405763-5718671.post@n5.nabble.com> References: <1346849405763-5718671.post@n5.nabble.com> From: Claus Ibsen Date: Thu, 6 Sep 2012 11:27:16 +0200 Message-ID: Subject: Re: How to act as TCP-client with Camel + Mina/Netty? To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 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 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