Saturday 12 November 2011

Configure JMS Resources and create Message Driven Bean in Websphere 7 (Step 6 and 7)

Step 6: Create a JMS Topic connection factory

Similar to step 2



Type TopicConnection for Name
jms/TopicConnectionFactory for JNDI name

Select InternalJMS as Bus name

Click ‘OK’ and save the changes

Step 7: Create a JMS Topic destination

Similar to step 3




Type Topic for name
jms/Topic for JNDI name
Select InternalJMS as Bus name
Type q for topic space identifier

Click ‘OK’ and save the changes

Configure JMS Resources and create Message Driven Bean in Websphere 7 (Step 5)

Step 5: Create a Queue Message Driven Bean

5.1 Create a Queue Activation Specification

Log into Websphere Application Server 7 Admin Console

Resources -> JMS -> Activation specifications



Click on ‘New’ button



Click on ‘OK’ button


Type QueueActSpec for Name
jms/QueueActSpec for JNDI name
Select Queue as Destination type
Type jms/Queue for Destination JNDI name
Select InternalJMS as Bus name

Click on ‘OK’ button (not shown in the screenshot)



Click on ‘Save’ link.

5.2 Create a queue message driven bean

@MessageDriven(name="queueMessageDrivenBean")
public class QueueMessageDrivenBean 
    implements MessageListener {

    @Override
    public void onMessage(Message message) {
        try {
            TextMessage txtMessage = (TextMessage) message;
            System.out.println(txtMessage.getText()
                    + " processed....Orz");
        } catch (JMSException ex) {
            throw new EJBException(ex);
        }
    }
}

In ibm-ejb-jar-bnd.xml

<message-driven name="queueMessageDrivenBean">
    <jca-adapter activation-spec-binding-name="jms/QueueActSpec"/>
</message-driven>

Test the servlet created in step 4 and check the result

[26/08/11 11:11:33:812 EST] 0000008f SystemOut O Message Sent
[26/08/11 11:11:33:812 EST] 000000a4 SystemOut O Hello World processed....Orz

Binding another message driven bean to the same queue destination won’t cause exceptions, but only one message driven bean is able to process the message.