3
votes

The need is to have a Camel (Mina/Netty) based TCP server running on a specific port, which allows multiple TCP clients to connect to it. The content to be streamed is available in files and the TCP server has to send each line in the text files to one of the connected clients (round robin).

Can someone help me with the outline of a camel route to achieve this?

Also it is possible to throttle the streaming speed for example 100 msg/sec per connected client?

Thanks in advance.

MK

1

1 Answers

3
votes

I have done something like this. Well not quite exactly to what you want but I can make some suggestions on how to get started.

Lets use the MINA component for this route as I had some issues with the Netty component see this link Exception thrown from Apache Camel Netty Consumer When more than one client sends data. Apparently this has been fixed but as my project got cancelled I never tested it again.

So from your description this will be a text line based protocol a simple route for this would look like this in the DSL

<route>
   <from uri="mina2:tcp://localhost:5555?textline=true"/>
   <to uri="bean:fileProcessing"/>
</route>

This route will open a listening socket on the localhost on port 5555. The route is also setup to use a textline codec. A textline codec is essentially a line of text terminated end of line character i.e. \n. If you are going to be using some other protocol you will need to look into the following items:

  • ProtocolEncoder—The ProtocolEncoder handles the task of taking an input payload and putting bytes onto the TCP channel.
  • ProtocolDecoder—The ProtocolDecoder interprets the custom binary protocol message to something your application can understand.
  • ProtocolCodecFactory— This creates the encoder and decoder.

You could implement some logic in the fileProcessing bean to send the replies back. There is a catch however the clients will have to request when they are ready to get a new line. From my understanding this follows a request reply scenario. However from what I have seen the route is only active when there is a message coming in from the client to the server.

There might be a way to initiate the sending from the server but you will need to experiment with that by yourself on getting it done I have not done anything like that myself.

Critical reading would be the following.

My suggestion is to start with a basic route like this and then expand your logic and then come back with problems you might encounter.

UPDATE:

So I did a little research on this and it does not appear possible to send events from the server to the client without following one of the following patterns InOnly and InOut.

Try just using MINA or Netty then.