queue mdb
package com.test;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
@MessageDriven(mappedName = "jms/fileQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")})
public class QueueMDB implements MessageListener {
public void onMessage(Message message) {
System.out.println("run ,i am a queue mdb ejb....");
if(message instanceof TextMessage){
TextMessage tm = (TextMessage) message ;
String user;
try {
user = tm.getStringProperty("user");
System.out.println(tm.getText() + ", user : "+user);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
topic mdb
package com.test;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
@MessageDriven(mappedName = "jms/fileTopic", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
@ActivationConfigProperty(propertyName = "clientId", propertyValue = "TopicMDB"),
@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "TopicMDB") })
public class TopicMDB implements MessageListener {
public void onMessage(Message message) {
System.out.println("run ,i am a topic mdb ejb....");
if(message instanceof TextMessage){
TextMessage tm = (TextMessage) message ;
String user;
try {
user = tm.getStringProperty("user");
System.out.println(tm.getText() + ", user : "+user);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}