Created
February 5, 2011 16:36
-
-
Save johnament/812571 to your computer and use it in GitHub Desktop.
Sample MDB that fires events.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tad.jms.jmsmanagingapp; | |
import javax.ejb.ActivationConfigProperty; | |
import javax.ejb.MessageDriven; | |
import javax.enterprise.event.Event; | |
import javax.enterprise.inject.spi.BeanManager; | |
import javax.inject.Inject; | |
import javax.jms.JMSException; | |
import javax.jms.Message; | |
import javax.jms.MessageListener; | |
import javax.jms.ObjectMessage; | |
import javax.jms.TextMessage; | |
import org.jboss.logging.Logger; | |
/** | |
* | |
* @author johnament | |
*/ | |
@MessageDriven(name="T4_MDB", activationConfig = | |
{ | |
@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Topic"), | |
@ActivationConfigProperty(propertyName="Destination", propertyValue="jms/LongT4") | |
}) | |
public class QueueHandlerMDB implements MessageListener{ | |
@Inject BeanManager beanManager; | |
@Inject Event<String> stringHandler; | |
Logger logger = Logger.getLogger(QueueHandlerMDB.class); | |
@Override | |
public void onMessage(Message message) { | |
if(message instanceof TextMessage) { | |
TextMessage tm = (TextMessage)message; | |
try{ | |
logger.info("Received text: "+tm.getText()); | |
} catch (JMSException e) { | |
logger.error("JMSException",e); | |
} | |
} else if(message instanceof ObjectMessage) { | |
ObjectMessage om = (ObjectMessage)message; | |
try{ | |
Object o = om.getObject(); | |
logger.info(o.getClass().getCanonicalName()); | |
logger.info("Object Data: "+o.toString()); | |
String s = o.toString(); | |
stringHandler.fire(s); | |
//beanManager.fireEvent(s); | |
} catch (JMSException e) { | |
logger.error("JMSException",e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment