How to create a JMS Queue on Weblogic Server

  1. Access the weblogic Admin console, typically http://localhost:7001/console;
  2. On Domain Structure, select Services -> Messaging -> JMS Servers;
  3. Click on New;
  4. Give your JMS Server a name, if you need your messages to be persisted, you should choose a Persistent Store method, mine is none;Image
  5. Click next and choose your server target, mine is AdminServer;
    Image
  6. Click Finish;
  7. Now that we have the server, we will create the queue, back on Domain Structure, select Services -> Messaging -> JMS Modules and the click New;
  8. Name your Module and give your descriptor file a name, can be the same as your Module name, if you don´t do that a default name will be given and it gets difficult to find it on the server files later;
    Image
  9. Select your server target;
    Image
  10. Next step asks if you want to create your queue right now, I will select the checkbox so I am forwarded to the queue creation screen;
    Image
  11. Now on your Module screen, click on the New button;
  12. The next screens shows you the resources you can create on that module, I will just select Queue;
    Image
  13. Next page asks you a name and a jndi name, even though the jndi name is not mandatory, you must name it so you can find your queue in the directory later;
    Image
  14. There is a next screen on sub-deployments, select or create a sub deployment pointing to your server and then Finish.

Create the Connection Factory

  1. To create the connection factory select Services -> Messaging -> JMS Modules -> and click the New button;
  2. Select Connection Factory and then Next;
  3. Select the server;
  4. Finish the config.

Testing the Queue

package com.wordpress.vrsbrazil.jmsQueue;

import java.util.Hashtable;

import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class QueueTest {

	public static void main(String[] args) throws NamingException, JMSException {

		Hashtable<String,String> props = new Hashtable<String,String>();
		props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
		props.put(Context.PROVIDER_URL, "t3://localhost:7101");

		Context ctx = new InitialContext(props);

		QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("jms/vrsJMSQueueCF"); //Connection Factory JNDI

		QueueConnection con = factory.createQueueConnection();

		QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

		Queue queue = (Queue) ctx.lookup("jms/vrsJMSQueue"); //Find the Queue

		QueueSender sender = session.createSender(queue); //Instantiating the message sender

		TextMessage message = session.createTextMessage("Message sent");

		con.start();

		sender.send(message);

		//Now receiving the message:

		QueueReceiver receiver = session.createReceiver(queue);

		TextMessage receivedMessage = (TextMessage)receiver.receive();

		System.out.println("Received message = " + receivedMessage);

	}

}

Thank you!

Advertisements

One thought on “How to create a JMS Queue on Weblogic Server”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s