How to publish JMS message concurrently in one connection

138 Views Asked by At

I want know how to publish JMS message concurrently to different topic.


Example: 1 thread to publish JMS message to topic X, 1 thread to publish JMS message to topic Y periodically (let say every 5 seconds)

How can achieve that?

Currently using Wildfly 8.3 (Hornetq) as JMS provider.

1

There are 1 best solutions below

0
Justin Bertram On

One simple solution would be to use Java's ScheduledExecutorService, e.g.:

ScheduledExecutorService ses = new ScheduledThreadPoolExecutor(2);
ses.scheduleWithFixedDelay(() -> sendJmsMessage(topicX), 0, 5, TimeUnit.SECONDS);
ses.scheduleWithFixedDelay(() -> sendJmsMessage(topicY), 0, 5, TimeUnit.SECONDS);