MDB's - Message Driven Beans
Einfache MDB:
@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"), @ActivationConfigProperty(propertyName="destination", propertyValue="queue/MyQueue") }) public class MyJmsBean implements MessageListener { public void onMessage (Message msg) { // ... } }
Senden einer Message an eine MDB:
try { InitialContext ctx = new InitialContext(); queue = (Queue) ctx.lookup("queue/MyQueue"); QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory"); cnn = factory.createQueueConnection(); sess = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); } catch (Exception e) { e.printStackTrace (); } TextMessage msg = sess.createTextMessage(...); sender = sess.createSender(queue); sender.send(msg);