JMS Queue listener and publisher using MDB in jboss using java

307 Views Asked by At

I have a requirement as :

Messages in a queue, say A, needs to be consumed by two different applications. I am trying to implement a MDB to listen to that queue and publish that msg to another topic from where applications can consume.

  1. Is it possible?
  2. Is it available readily as some config in jboss..am I reinventing the wheel?
  3. Any help on this to achieve..

Code:

@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "queue/test.queue"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue") })
public class MyListener implements MessageListener {

private JmsTemplate jmsTemplate;

public MyListener(JmsTemplate jmsTemplate) {
    this.jmsTemplate = jmsTemplate;
}

public void onMessage(Message message) {
    System.out.println("Message received");
    // TextMessage textMessage = (TextMessage) message;
    publishMessage(message);
    System.out.println("Message re-published");
}

Thanks in advance.

1

There are 1 best solutions below

2
Justin Bertram On

If the same message needs to be consumed by 2 different applications then both applications should subscribe to the same topic and the message should be sent to that topic. That way both applications will get the message and you won't need to waste your time resending the message yourself.