2

I use JavaEE 8 on Liberty 18.0.0.2 .
I setup jms activation config like this (server.xml):

  <messagingEngine>
    <queue id="application" />
  </messagingEngine>
  <jmsActivationSpec id="app/appMDB">
    <properties.wasJms destinationRef="java:app/onlineQueue" />
  </jmsActivationSpec>   

And this is my simple MDB message listener :

@MessageDriven(
        name = "appMDB",
        mappedName = "java:app/onlineQueue",
        activationConfig = {
                @ActivationConfigProperty(propertyName = "destinationType",
                        propertyValue = "javax.jms.Queue"),
                @ActivationConfigProperty(propertyName = "destination",
                        propertyValue = "java:app/onlineQueue")
        }
)
public class ApplicationMessageListener implements MessageListener {
...
}

And also I defined two queues like this :

@Stateless
@JMSDestinationDefinitions(
        value = {
                @JMSDestinationDefinition(
                        name = "java:app/onlineQueue",
                        interfaceName = "javax.jms.Queue",
                        destinationName = "application"),
                @JMSDestinationDefinition(
                        name = "java:app/offlineQueue",
                        interfaceName = "javax.jms.Queue",
                        destinationName = "application")
        }
)
public class MessageService {

    @Inject
    private Logger logger;

    @Resource(lookup = "java:app/onlineQueue")
    private Queue onlineQueue;

    @Resource(lookup = "java:app/offlineQueue")
    private Queue offlineQueue;

    @Inject
    private JMSContext context;

    @EJB
    private MessageUtils messageUtils;

    public void sendToOnlineQueue(SimpleMessage simpleMessage) {
        TextMessage message = messageUtils.createTextMessage(simpleMessage);
        logger.info("Send online Message : " + simpleMessage);
        JMSProducer producer = context.createProducer();
        producer.send(onlineQueue, message);
    }

    public void sendToOfflineQueue(SimpleMessage simpleMessage) {
        TextMessage message = messageUtils.createTextMessage(simpleMessage);
        logger.info("Send offline Message : " + simpleMessage);
        JMSProducer producer = context.createProducer();
        producer.send(offlineQueue, message);
    }
}   

My problem is MDB listen to multiple queues .
I want mdb only listen to onlineQueue .
How can fix this problem ?

mah454
  • 1,571
  • 15
  • 38
  • What evidence is there that the MDB is listening to multiple queues? – Justin Bertram Oct 22 '18 at 17:59
  • I send message to offlilneQueue but online message listener want to handle that . – mah454 Oct 22 '18 at 18:12
  • 1
    You are using two instances of `@JMSDestinationDefinition` to define two queues, but they both have the same `destinationName` (i.e. `application`). That seems wrong to me. Also, your MDB is using an `@ActivationConfigProperty` named `application` which also seems wrong. This should probably named `destination`. – Justin Bertram Oct 22 '18 at 18:20
  • Opss , Sorry I updated post about property name (destination) . – mah454 Oct 22 '18 at 18:26
  • I confused ! you say per queue must define different destination name ? – mah454 Oct 22 '18 at 18:27
  • You have two different `@JMSDestinationDefinition`. One has the `name` of `java:app/onlineQueue`, and the other has the `name` of `java:app/offlineQueue`. However, both of them have the `destinationName` of `application` which seems wrong to me. Whether you look up `java:app/onlineQueue` or `java:app/offlineQueue` in JNDI you'll get a reference to a destination named `application`. This is almost certainly why messages sent to `java:app/offlineQueue` are picked up by the MDB. – Justin Bertram Oct 22 '18 at 19:11
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/182293/discussion-between-mah454-and-justin-bertram). – mah454 Oct 22 '18 at 20:55

1 Answers1

1

You have two different @JMSDestinationDefinition. One has the name of java:app/onlineQueue, and the other has the name of java:app/offlineQueue. However, both of them have the destinationName of application which seems wrong to me. Whether you look up java:app/onlineQueue or java:app/offlineQueue in JNDI you'll get a reference to a destination named application. This is almost certainly why messages sent to java:app/offlineQueue are picked up by the MDB.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43