0
votes

Greeting, I'm new to Java EE and especially message driven bean so i followed the tutorial which has been working with internal JMS destinations (e.g. weblogic server that runs on my local machine). Now I'm trying to listen to new messages from remote destinations (e.g. another weblogic server run on different machine). I'm thinking about jndi naming lookup however I don't see any appropriate place to implement in the MDB. My question is do I need any config files in order for this to work? or is it even possible to listen to remote JMS destinations?

@MessageDriven(mappedName="jms/myQueue") //jms/myQueue is remote queue name
public class PMQueueListener implements MessageListener{
    @Resource
    private MessageDrivenContext mdc;

    /**
     * Default constructor. 
     */
    public PMQueueListener() {
        System.out.println("This is onmessage()");
    }


    /**
     * @see MessageListener#onMessage(Message)
     */
    public void onMessage(Message message) {
        TextMessage msg = null;
        try 
        { 
            if (message instanceof TextMessage) 
            {
                msg = (TextMessage) message;
                System.out.println("MESSAGE BEAN: Message received: " +
                    msg.getText());
            } 
            else 
            {
                System.out.println("Message of wrong type: " +
                        message.getClass().getName());
            }
        } 
        catch (JMSException e) 
        {
            e.printStackTrace();
            mdc.setRollbackOnly();
        } 
        catch (Throwable te) 
        {
            te.printStackTrace();
        }

    }

}
1

1 Answers

0
votes

You can add below annotation on your MDB and see if it works for you.

@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)