Forum Home » Fuse Distributions » Fuse Mediation Router

Thread: Simple Camel-Netty Examples/Issue?

 
This question is answered.


Permlink Replies: 12 - Last Post: Mar 12, 2012 8:03 AM Last Post By: davsclaus
dr8ball

Posts: 9
Registered: 02/03/12
Simple Camel-Netty Examples/Issue?
Posted: Mar 6, 2012 5:21 AM
 
  Click to reply to this thread Reply
Is there any good examples using the camel-netty component? We have a project in which we want to route some XML messages from a TCP connection to a JMS topic vice versa. At first I thought that camel-netty or camel-mina would be perfect for this. After some research it appeared that camel-netty is preferred over camel-mina so I started with a simple example. I currently have a timer feeding messages to a topic which is then sent out via netty, unfortunately it appears that only the first message is received by the server. Any ideas?

from("activemq:topic:topic.tcp.1.out")
.to("netty:tcp://localhost:4444?textline=true&sync=false");

davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 6, 2012 8:55 AM   in response to: dr8ball in response to: dr8ball
 
  Click to reply to this thread Reply
Are you sure the receiver is using the same codec as you? eg you specify textline, which means its a text based codec, that terminates with a newline.

You can add a .to("log:from-topic") in the route, so you can see in the log that you receive more messages from the topic.
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 6, 2012 8:56 AM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
Also you may want to use the old camel-mina component, until this bug is fixed in camel-netty: https://issues.apache.org/jira/browse/CAMEL-4556
dr8ball

Posts: 9
Registered: 02/03/12
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 7, 2012 3:50 AM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
Thanks for the quick reply Claus. I have been enjoying your book "Camel in Action" and am looking forward to using FUSE. I have tinkered with Camel and FUSE ESB before but this is my first time to get to use it for one of our projects. If we can get this to work then my hope is that we will use it more.

The short answer is no, they are not using the same "codec", and yes multiple messages are being sent to my topic destination. My test is using just a basic BufferedReader wrapping an InputSteamReader for the server. What exactly do you mean when you say "terminates with a newline"?

The end goal is for camel-netty to be the bridge between an external TCP Server/Client and JMS topics. We do not have any control over the "External" server/client.

External TCP Server -> camel-netty-> some.topic.in -> Application (xml payload)

External TCP Client <- camel-netty <- some.topic.out <- Application (xml payload)

davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 7, 2012 8:21 AM   in response to: dr8ball in response to: dr8ball
 
  Click to reply to this thread Reply
Hi

We have some unit tests in camel-netty. For example this in only textline test
https://svn.apache.org/repos/asf/camel/trunk/components/camel-netty/src/test/java/org/apache/camel/component/netty/NettyTextlineInOnlyTest.java

Notice how we use \n to terminate the message. eg the textline codec needs a new line character at the end, so it knows when the message ends.
dr8ball

Posts: 9
Registered: 02/03/12
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 9, 2012 4:29 AM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
After some more testing it appears that camel-netty client closes the socket after each message sent, since my test application was only accepting a single connection I was only seeing the first message. I did not see this behavior when testing with the camel-mina component. Is there something that I am missing in the configuration that would allow camel-netty to reuse the socket?

Is there any reasons that we should choose the camel-mina component over the camel-netty component? Are you planning to support both equally or is one preferred over the other?
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 9, 2012 5:39 AM   in response to: dr8ball in response to: dr8ball
Helpful
  Click to reply to this thread Reply
FuseSource supports all what we offer in our products.

The camel-mina component is using the older Mina 1.x. There is a new camel-mina2 component in the works for Camel 2.10, that is using the new Mina 2.x releases.
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 9, 2012 5:40 AM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
That said, a lot of people is using the camel-mina component since it has been there for a very long time, and it just works.
dr8ball

Posts: 9
Registered: 02/03/12
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 10, 2012 4:47 AM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
OK, I think you have convinced me to go back to the camel-mina or camel-mina2 component but just so that I know, is there a way to prevent camel-netty from closing the socket after each message?

Regarding camel-mina2, is there a way to create a consumer that acts as a client instead of a server? I have seen the question in other threads but I wasn't sure if and how that would work in the camel-mina2 component. If not, is there a work around?
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 10, 2012 8:25 AM   in response to: dr8ball in response to: dr8ball
Helpful
  Click to reply to this thread Reply
There is some JIRAs to enhance camel-mina2 to let it act as a client as well. Somebody from the community said he wanted to contribute and works on it.
dr8ball

Posts: 9
Registered: 02/03/12
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 12, 2012 5:09 AM   in response to: davsclaus in response to: davsclaus
 
  Click to reply to this thread Reply
Thanks for the info Claus! Is there a way that I can get in contact with the person who is working on this? I have an immediate need and if possible would like to either test the current solution or aid with a new solution.

Also, I would still like to know if there is a solution to my netty question so that I can mark it as answered. Is there a way to prevent camel-netty from closing the socket after each message?
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 12, 2012 8:00 AM   in response to: dr8ball in response to: dr8ball
 
  Click to reply to this thread Reply
Well camel-netty has the disconnect option, that by default is false
http://camel.apache.org/netty

To get in touch with the guy then try to find the ASF Camel JIRA ticket and post a comment there. And/or post on the Camel @user mailing list to get attention.

If you are a FuseSource subscriber you can use that channel to get help with this, such as influence our roadmap, get direct access to our engineering team who can help speedup this etc.
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Simple Camel-Netty Examples/Issue?
Posted: Mar 12, 2012 8:03 AM   in response to: davsclaus in response to: davsclaus
Correct
  Click to reply to this thread Reply
A new connection is created each time due this bug reported here
https://issues.apache.org/jira/browse/CAMEL-4556