简体   繁体   中英

Connecting to TCP and consuming JMS topic

  • I have a JMS topic. Data is constantly being written to this topic.
  • I want to expose a tcp listening port that, when connected, displays streams of data.
  • 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. so instead of "tail -f ", it is more like "telnet server1 40000" to view the contents of the topic.

currently I am thinking about using netty.io, but not sure if spring-integration can handle it.

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.

  • 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
  • client #2 connects to tcp port 40000, topic string content is being written to the socket
  • both client #1 and client #2 get the same data
  • currently there are 2 consumers for the topic
  • client #2 disconnects
  • number of consumer for the topic is back to being 1
  • client #1 still gets data streamed

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.

You need inbound and outbound TCP adapters.

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).

When the client closes the connection, you'll get a connection closed event; stop the topic consumer and unregister it.

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