deltanovember
deltanovember

Reputation: 44041

Does the JMS API support asynchronous bidirectional messaging?

The examples I have seen seem to support several use cases:

  1. Point to point - single publisher to single consumer, unidirectional communication from publisher to consumer
  2. Publish/subscribe - publisher to multiple consumers, unidirectional communication from publisher to consumer
  3. Request/response - single publisher to single consumer, bidirectional communication but blocking

What I'm looking for is bidirectional asynchronous messaging. For example I would like to do the following

Publisher: "Hello world" to consumer
Consumer: Process "Hello world"

Wait 5 minutes

Consumer: "Hello publisher" to publisher
Publisher: Process "Hello publisher"

Does the API support the above use case? Or would I need to implement everything as publisher and consumer concurrently?

Upvotes: 2

Views: 2039

Answers (5)

javorsh
javorsh

Reputation: 1

You can try with websocket (SockJS) . In every message from client can add the client Id. Sending it to server , the message broker will redirect it back to all clients (/topic) and by client Id will distinguish the sender .

Upvotes: 0

Denys
Denys

Reputation: 31

You can use Apache Camel http://camel.apache.org/ and work with JMS component to send a message in In/InOut way. Camel creates a temporary queue to send an answer back for every request if you use inOut way. Also it provides a lot possibilities for varied message processing and message content enrichment on-fly.

Upvotes: 0

Pursuit
Pursuit

Reputation: 12345

Most likely your best bet is to use 2 queues. The same object on each side can be a producer on one queue and a consumer on the other. Then you have:

Object1 "Hello world" -> queueDirection1 ->  Object2 processes "hello world" 
Object2 "Hello world" -> queueDirection2 ->  Object1 processes "hello world" 

This is now completely asynchronous, with no timing requirements between the queues.

I think that any configuration with a single queue or a single topic presents a risk of undesired blocking, or perhaps self-receiving a message. Be sure to consider how the system will behave if the message rate increases, or the processing time increases.

Upvotes: 2

Shashi
Shashi

Reputation: 15263

JMS does not have any API for your requirement. You can implement your requirement using point to point messaging.

Publisher "Hello World" -> Q1 -> Consumer processes "Hello World".

Wait 5 seconds

Consumer says "Hello World" -> Q1 -> Publisher processes "Hello World"

Upvotes: 0

stratwine
stratwine

Reputation: 3701

I have not tried this myself, but an implementation that uses JMSReplyTo might be a way to go about this.

Check this How should I implement request response with JMS? doc from ActiveMQ

Upvotes: 0

Related Questions