Question

My project publishes RESTful/SOAP services. One of these sends messages to a JMS queue on a Websphere application server. The application runs on the same application server. What I need is to define a listener to this queue. How can I activate this listener without a direct call from the service?

The project structure looks like this:

Project:
  -ejb
  -rest
  -soap

The user calls methods on the service, which calls the EJB component, so I dont have any main method where I can init the listener.

I need a solution which activates a permanent listener to the queue.

I already have the source code I just don't know how to initialize the listener.

Was it helpful?

Solution 2

WebSphere MDB with a lot of configuration it works!!!! But look at this:

    @MessageDriven(activationConfig={
                @ActivationConfigProperty(propertyName="destination",     propertyValue="myDestination"),
                @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue")
})
public class MsgBean implements javax.jms.MessageListener {

  public void onMessage(javax.jms.Message msg) {

      String receivedMsg = ((TextMessage) msg).getText();
      System.out.println("Received message: " + receivedMsg);

   }

}

OTHER TIPS

Not sure where you have the issues:

Do something like:

  • define the JMS resources in WebSphere
  • inject the javax.jms.Queue as a Resource (or maybe using CDI? Not sure if CDI supports this) in a EJB
  • use this Queue to send messages
  • define a MDB (@MessageDriven) to listen for messages
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top