Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
28. Jul 2008, 20:26 CET | Link

Since I could not find a simple example demonstrating Seam-MDB (Mesage Driven Bean) usage, I am posting one for the benefit of others. We will create a simple EJB3 MDB called "Phone" and send a message to it from a EJB3 stateless bean (I assume you know how to create and use stateless beans).

In 3 steps:

Step 1: Here is the code for the MDP (Phone.java):
-----------------------------------------------------
package com.mkl.message;

import javax.jms.*;
import javax.ejb.MessageDriven;
import javax.ejb.ActivationConfigProperty;

@MessageDriven(name="PhoneMessageBean", activationConfig = {
     @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
     @ActivationConfigProperty(propertyName="destination", propertyValue="queue/phoneQueue")
 })
public class Phone implements MessageListener {

 @Override
 public void onMessage(Message msg) {
  // TODO Auto-generated method stub
  TextMessage textMsg = (TextMessage) msg;
  try {
   System.out.println("Received Phone Call:" + textMsg.getText());
  } catch (JMSException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}
    -----------------------------------------------------

Step 2: Here is the component addition to components.xml

-----------------------------------------------------
<component name="phoneQueueSender"
          class="org.jboss.seam.jms.ManagedQueueSender">
    <property name="queueJndiName">queue/phoneQueue</property>
</component>

-----------------------------------------------------

Step 3: Here is the stateless bean function which sends a message
(YOU NEED TO IMPORT javax.jms.*)
-----------------------------------------------------
 @In(create=true)
 private transient QueueSender phoneQueueSender;
 @In(create=true)
 private transient QueueSession queueSession;

 public void make_a_call (){
       try
       {
          phoneQueueSender.send( queueSession.createTextMessage("You are in trouble"));
       }
       catch (Exception ex)
       {
       ex.printStackTrace();
          throw new RuntimeException(ex);
       }
    }

-----------------------------------------------------

5 Replies:
28. Jul 2008, 23:32 CET | Link

Vote for this to be pu tin Manual/FAQ +1

 

But I being poor have only my dreams. I have spread my dreams under your feet. Tread softly because you tread on my dreams...

01. Aug 2008, 20:31 CET | Link
I am new to this forum - how do I put this example in Manual/FAQ?
01. Aug 2008, 21:03 CET | Link

You could just add it here

 
Please don't forget to rate

I believe that imagination is stronger than knowledge -- myth is more potent than history -- dreams are more powerful than facts -- hope always triumphs over experience -- laughter is the cure for grief -- love is stronger than death.

01. Aug 2008, 21:13 CET | Link

I believe you can do the components.xml part simpler -


<jms:managed-queue-sender name="phoneQueueSender" auto-create="true" queue-jndi-name="queue/phoneQueue"/>

... at least thats how we are doing it.

Also if you are going to post it on hte FAQ, i'd suggest finishing the makeacall class so it has a @Name annotation etc ... just so people dont get confused.

02. Aug 2008, 02:52 CET | Link
Thanks all. I have put it in the KB (tips & tricks) - incorporated your sugs as well.