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);
}
}
-----------------------------------------------------
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...
You could just add it here
Please don't forget to rate!
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. - Antoine de Saint Exupéry
Please visit my blog
I believe you can do the components.xml part simpler -
... 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.