简体   繁体   English

如何在WSO2 ESB中调解纯TCP消息

[英]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). 我有一个应用程序(比方说,TcpApp)发送纯TCP消息(即没有SOAP,没有信封......只是一个原始字符串甚至字节)。 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). 我需要连接ESB以通过特定端口(例如,3333)监听这些消息,并进行一些调解(现在,只做日志记录就足够了)。 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). 我认为从TcpApp创建ActiveMQ队列然后在ESB中从JMS创建代理服务(而不是直接将ESB连接到TcpApp)是个好主意。 I read several samples and answers, but always the contect is XML, and TCP is only the transport. 我阅读了几个示例和答案,但始终是XML,TCP只是传输。 What sometime happens is that applications send no special formats over TCP (sometime called telegrams). 有时会发生的是应用程序不通过TCP发送特殊格式(有时称为电报)。 I tried to change the content type, but still the ESB refuses to read the TCP port. 我试图更改内容类型,但ESB仍然拒绝读取TCP端口。

<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. 可能我仍然对解决方案的体系结构感到困惑,但我认为像这个TcpApp这样的经纪人,或像WSO2这样的ESB应该可以工作。 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. 在WSO2 EI 6.1.1中,我发现如果我还指定了recordDelimiter和recordDelimiterType,我可以成功处理纯文本TCP消息。 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. 在axis2.xml文件中使用以下格式化程序。

<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] :)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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