Weblogic JMS & MDB Quickstart Guide?


I want to use Message Driven Beans within Weblogic 7. In order to do this I want a (simple) working JMS Server with a Queue from which my MDB can consume. Having tried to work through the online help docs and experienced much pain (too much to configure, I just want a simple life!), I thought I would see if there is an easier way! So the following are what I would like:

JMS Server: BTNBJMSServer
Queue: CustomTaskQueue

MDB: MessageTFJ2EETranslatorEJB

That is it. I have created the Bean and deployed it to Weblogic successfully (well it doesn't give any errors). The problem is with the JMS side of things. Can someone give me a step by step guide to creating a simple server with a queue that I can use from within my MDB? Also how can I test my MDB? I don't see an option to put messages onto queues from the Weblogic console? Do I need to write a Java app to act as the producer and put messages onto the queue for the MDB?  

The following are the two descriptors and the MDB itself. Is there anything missing?:

ejb-jar.xml -


weblogic-ejb-jar.xml -


The MDB itself is as follows:

public class MessageTFJ2EETranslatorBean
        implements MessageDrivenBean, MessageListener
    private MessageDrivenContext ctx;

    public MessageTFJ2EETranslatorBean()

    public void onMessage(Message message)
        System.out.println("Message received: ");
            if (message instanceof TextMessage)
                System.out.println("TextMessage: " + ((TextMessage) message).getText());
            else if(message instanceof ObjectMessage)
                System.out.println("ObjectMessage: " + ((ObjectMessage)message).getObject());
            else if(message instanceof StreamMessage)
                System.out.println("StreamMessage: " + ((StreamMessage)message).readString());
            else if(message instanceof BytesMessage)
                System.out.println("BytesMessage: " + ((BytesMessage)message).readUTF());
            else if(message instanceof MapMessage)
                System.out.println("MapMessage: " + ((MapMessage)message).getString("msg"));
        catch (JMSException e)
            System.out.println("JMSException in onMessage(): " + e.getMessage());

    public void ejbRemove()
            throws EJBException

    public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext)
            throws EJBException
        this.ctx = messageDrivenContext;

    public void ejbCreate()
            throws CreateException
        System.out.println("Message Driven Bean Created");

Who is Participating?
sompol_kiatkamolchaiConnect With a Mentor Commented:
Hello scurtis,

You have 2 problem.

1.How to configure JMS server in WebLogic 7.
2.How to send message to queue.

1.Since I doesn't have version 7, I will guide you by follow admin ui in version 8. I think it's not different too much. You can follow the step below to configure it.

Create JMSServer
-Logon to administrator console "http://localhost:7001/console"
-Go to menu on the left pane "Services/JMS/Servers/"
-On the right pane click on the link "Configure a new JMSServer"
-Put the name(e.g. jmsserver1) of JMSServer and then click create button
-Target and deploy JMSServer on the server of WebLogic domain and then click apply button

Create queue destination
-Logon to administrator console "http://localhost:7001/console"
-Go to menu on the left pane "Services/JMS/Servers/jmsserver1/Destinations"
-On the right pane click on the link "Configure a new JMSQueue"
-Put the name of queue and JNDI name for MDB to consume.

2.Here is an example code to produce message to queue
InitialContext context = new InitialContext();
QueueConnectionFactory factory = (QueueConnectionFactory)context.lookup("javax.jms.QueueConnectionFactory");
QueueConnection con = factory.createQueueConnection();
QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = (Queue)context.lookup("CustomTaskQueue");
QueueSender sender = session.createSender(queue);
TextMessage msg = session.createTextMessage();
msg.setText("Hello World!");

Hope this help & Best luck to you.

scurtis_1Author Commented:

Thanks for that. The JMS server and the message producer class now work! :-)

Unfortunately, my Message Driven Bean deploys but the onMessage method is never called? I know messages are available (ie making it onto the queue) as I can see them when I Monitor my CustomTaskQueue in the Weblogic Console?

Any ideas would be kindly received?


P.S. I have looked through the thread "What's wrong with my FIRST MessageDrivenBean :(" and none of the suggestions seem to help?
scurtis_1Author Commented:
Ok, worked it out. In my Producer I was using the following line:

session = connection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);

By setting the boolean (transacted) parameter to false it is now picking up the messages from the queue. The problem is that it doesn't do a destructive read, only a 'browse' and it only ever picks up any new incoming messages, not those that were already on the queue when the bean was created?

Can anyone tell me how to make my bean consume the messages from the queue and how to make it pick up any waiting messages when it first starts up?

scurtis_1Author Commented:
Ok, I was being dumb! I was expecting something like 'Queue Depth' which would show the number of messages still waiting, but in Weblogic JMS it appears to be called 'Messages High'?

Oh well, that just about wraps this thread up. Thanks again for your help SOMPOL and enjoy the points! :-)

All Courses

From novice to tech pro — start learning today.