简体   繁体   中英

How to mediate pure TCP messages in WSO2 ESB

I have an application (say, TcpApp) sending pure TCP messages (ie, no SOAP, no envelope ... just a raw string or even bytes). I need to connect ESB to listen those messages over a specific port (say, 3333), and make some mediation (for now, do nothing but logging is enough). I think it would be a good idea to make an ActiveMQ queue from TcpApp and then to make a proxy service from JMS in the ESB (instead of connect directly the ESB to the TcpApp). I read several samples and answers, but always the contect is XML, and TCP is only the transport. What sometime happens is that applications send no special formats over TCP (sometime called telegrams). I tried to change the content type, but still the ESB refuses to read the TCP port.

<parameter name="transport.tcp.contentType">text/plain</parameter>

May be I'm still confuse with the architecture of the solution, but I think a Broker, or an ESB like WSO2, should work is this case as a mediator from this TcpApp. I prefer to disscus the solution before to get the real config to make it work. All comments, welcomed!

In WSO2 EI 6.1.1, I have found that I can successfully process plain text TCP messages if I also specify a recordDelimiter and recordDelimiterType. Example from a working proxy (with the line feed character as delimiter):

<parameter name="transport.tcp.responseClient">true</parameter>
<parameter name="transport.tcp.inputType">binary</parameter>
<parameter name="transport.tcp.recordDelimiter">0x0A</parameter>
<parameter name="transport.tcp.contentType">text/plain</parameter>
<parameter name="transport.tcp.port">50001</parameter>
<parameter name="transport.tcp.recordDelimiterType">byte</parameter>

The message body in the input sequence looks like this:

<text xmlns="http://ws.apache.org/commons/ns/payload">this_is_the_message</text>

You need to use the correct message formatters and builders to process anything. Use following formatters in the axis2.xml file.

<messageFormatter contentType="application/binary" class="org.wso2.carbon.relay.ExpandingMessageFormatter"/>
<messageBuilder contentType="application/binary" class="org.wso2.carbon.relay.BinaryRelayBuilder"/>

Just change the content type whatever you like and use the same in the proxy service config as well. Actually I have a blog post on this as well [1] :)

[1] - http://soatechflicks.blogspot.com/2017/05/processing-binary-data-from-tcp.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM