Wednesday, December 9, 2009

WebSphere SIB, JMS queues and connection factory configuration

I was recently given a task to migrate an enterprise application that was running on SAP NetWeaver across to WebSphere application server. The application had a few session beans as well as a few message-driven beans. It used JMS to publish messages to a number of queues. This blog entry outlines the steps I took to configure the JMS queues and connection factories on WebSphere. It is pretty plain and boring but is really for my own benefit to be used as a reference and who knows maybe if you are reading this it may come in handy as well.

The following configurations were done on a single server of WebSphere application server 7.0. It assumes that the user is logged into the administration console and where global security has been enabled:

Create J2C authentication user
  • Security -> Global security -> Expand Java Authentication and Authorization Service -> J2C authentication data -> New
  • Enter in the following values:
    • Alias: myusr
    • User ID: myusr
    • Password: myusr
  • Click the OK button
  • Save to the master file configuration

Create group
  • Users and Groups -> Manage Groups -> Create
  • Enter in the following values:
    • Group name: mygrp
  • Click on the Group Membership button
  • Add the mygrp
  • Click the close button

Create user
  • Users and Groups -> Manage Users -> Create
  • Enter in the following values:
    • User ID: myusr
    • First name: Myusr
    • Last name: Mysurname
    • Password: mypassword
    • Confirm password: mypassword
  • Click on the Group Membership button
  • Click the Search button
  • Add the mygrp
  • Click the Close button
  • Click the Create button

Create SIB
  • Service integration -> Buses -> New
  • Bus Name: my_bus
  • Bus Security: enabled
  • Press next to enter the security wizard
  • Complete the wizard by accepting all the defaults
  • Save your changes by clicking the save link

Configure Authorization for the SIB
  • Service integration -> Buses
  • Select the Enabled link for the my_bus
  • [Authorization Policy] -> Users and groups in the bus connector role -> New
  • Enable Groups radio button and click the Next button
  • Select the mygrp checkbox and then the Next button
  • Click the OK button
  • Save to the master file configuration

Create Bus member for SIB
  • Service integration -> Buses -> my_bus -> [Topology] Destinations -> Bus members -> Add button
    • Enable the server radio button
  • Click the Next button
    • Enable the File store radio button
  • Finish the wizard by accepting all defaults
  • Save to the master file configuration

Create destinations for SIB
  • Service integration -> Buses -> my_bus -> [Destinations resources] Destinations -> New
  • Type: Queue
  • Next
  • Identifier: myFirstD
  • Select the bus member you created in the previous step
  • Finish the wizard by accepting all defaults
  • Save to the master file configuration

Configuring authorization on queue destinations
Optional because already has AllAuthenticated by default however it is recommended to remove this and add your own
  • Service integration -> Buses
  • Select the Enabled link for the my_bus
  • [Authorization Policy] -> Manage destination access roles
  • Select the myFirstD destination
  • Select the Add button
  • Enable Groups radio button and click the Next button
  • Select the mygrp checkbox and then the Next button
  • Check the Sender, Receiver and Browser checkboxes
  • Click the Finish button
  • Click the OK button
  • Save to the master file configuration

Create Connection Factory (Can also create Queue / Topic Connection Factory in a similar way)
  • Resources -> JMS -> Connection factories -> select server scope from the drop down list -> New
  • Default messaging provider -> Next
  • Enter in the following values:
    • Name: MyConnectionFactory
    • JNDI name: jms/MyConnectionFactory
    • Bus name: my_bus
    • Container-managed authentication alias: myusr
  • Click the OK button
  • Save to the master file configuration

Create JMS Queues (Can also create Topics in a similar way)
  • Resources -> JMS -> Queues -> select server scope from the drop down list -> New
  • Select the Default messaging provider radio button
  • Click the OK button
  • Enter in the following values:
    • Name: myFirstQ
    • JNDI name: jms/myFirstQ
    • Bus name: my_bus
    • Queue name: myFirstD
  • Select the OK button
  • Save to the master file configuration

Create Activation specifications
  • Resources -> JMS -> Activation specifications -> select server scope from the drop down list -> New
  • Select the Default messaging provider radio button
  • Click the OK button
  • Enter in the following values:
    • Name: myFirstSpec
    • JNDI name: eis/myFirstSpec
    • Destination type: Queue
    • Destination JNDI name: jms/myFirstQ
    • Bus name: my_bus
    • Authentication alias: myusr
  • Select the OK button
  • Save to the master file configuration

That's all there is to it. The next step will be configuring you application's resources and assigning them the correct authentication methods. I will describe those steps in my next blog along with a sample application.

5 comments:

Tamonas said...

 Following are the next steps to send a message the queue and received the message from the queue :

Tamonas Datta said...

1. Create one Dynamic web project.
2. Create one servlet
3. Put the following code in the init method of the servlet
 public void init() throws ServletException {
        try{
                //code for creating the connection
                InitialContext init = new InitialContext();
               
                javax.jms.Queue destination =(javax.jms.Queue) init.lookup("jms/myFirstQ");
                connectionFactory = (ConnectionFactory) init.lookup("jms/MyConnectionFactory");
                connection = connectionFactory.createConnection();
                session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                connection.start();
                System.out.println("connection is ready");
               
                //code for message producer
                TextMessage message = session.createTextMessage();
                message.setText("My text message for send and received");
                MessageProducer producer = session.createProducer(destination);
                producer.setDeliveryMode(DeliveryMode.PERSISTENT);
                producer.send(message);
                System.out.println("message is sent to the queue");
               
                //code for consumer
                MessageConsumer consumer = session.createConsumer(destination);
                Message receivedMessage = consumer.receive(1000);
                connection.close();
                System.out.println("received message  "+receivedMessage);               
            }catch (Exception e) {
            System.out.println(e.getMessage());
        }
    } 


From the console u will get the logs that message was sent and received using the JMS.

rmahony said...

thanks for sharing Tamonas

S_K_B said...

Where is the use of "user" inside the sample code  & activation spec definition? 

S_K_B said...

Also, if you can provide some samples with ejb2.* with MDB along with configuration ,that would be much helpful