简体   繁体   English

连接到TCP并使用JMS主题

[英]Connecting to TCP and consuming JMS topic

  • I have a JMS topic. 我有一个JMS主题。 Data is constantly being written to this topic. 数据一直在被写入该主题。
  • I want to expose a tcp listening port that, when connected, displays streams of data. 我想公开一个tcp侦听端口,该端口在连接时显示数据流。
  • The data is what ever is the latest content of the topic 数据是该主题的最新内容

basically, i want to do a "tail -f" on a jms topic using tcp port. 基本上,我想使用tcp端口对jms主题执行“ tail -f”操作。 so instead of "tail -f ", it is more like "telnet server1 40000" to view the contents of the topic. 因此,代替“ tail -f”,它更像是“ telnet server1 40000”来查看主题的内容。

currently I am thinking about using netty.io, but not sure if spring-integration can handle it. 目前,我正在考虑使用netty.io,但不确定spring-integration是否可以处理它。

has anybody even done something like this? 有人做过这样的事情吗?

using a message listener would be great, except, i only want to consume the topic when a tcp connection is established. 使用消息监听器会很好,除了,我只想在建立TCP连接时使用该主题。

  • server starts. 服务器启动。
  • no thing is being read from the topic 该主题没有任何内容
  • client #1 connects to tcp port 40000, topic string content is being written to the socket 客户端#1连接到TCP端口40000,主题字符串内容正在写入套接字
  • client #2 connects to tcp port 40000, topic string content is being written to the socket 客户端#2连接到TCP端口40000,正在将主题字符串内容写入套接字
  • both client #1 and client #2 get the same data 客户端#1和客户端#2都获得相同的数据
  • currently there are 2 consumers for the topic 目前有2位该主题的消费者
  • client #2 disconnects 客户端#2断开连接
  • number of consumer for the topic is back to being 1 该主题的消费者人数回到1
  • client #1 still gets data streamed 客户端#1仍获取数据流

Thanks. 谢谢。

It's pretty easy to set up a service that responds to a TcpConnectionOpenEvent by opening a consumer to the JMS topic and streaming the messages to the connection. 通过打开JMS主题的使用者并将消息流式传输到连接,设置响应TcpConnectionOpenEvent的服务非常容易。

You need inbound and outbound TCP adapters. 您需要入站和出站TCP适配器。

When the inbound adapter detects a new connection it emits the event. 当入站适配器检测到新连接时,它将发出事件。 Use an ApplicationListener (or even inbound adapter) to catch the event, capture the connection ID, open a consumer on the topic and start sending messages to the outbound adapter (set the ip_connectionId so the adapter knows where to route the message). 使用ApplicationListener (或什至入站适配器)来捕获事件,捕获连接ID,在主题上打开使用者并开始将消息发送到出站适配器(设置ip_connectionId以便适配器知道将消息路由到何处)。

When the client closes the connection, you'll get a connection closed event; 当客户端关闭连接时,您将收到一个连接关闭事件。 stop the topic consumer and unregister it. 停止主题使用者并取消注册。

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

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