List of usage examples for javax.jms QueueReceiver setMessageListener
void setMessageListener(MessageListener listener) throws JMSException;
From source file:com.npower.dm.multiplexor.Multiplexor.java
public void init(ActionServlet arg0, ModuleConfig arg1) throws ServletException { log.info("Starting SMS Multiplexor Daemon ..."); connection = null;/*from w w w . jav a2 s .c o m*/ session = null; try { // Load Mapping Table this.mappingTable = this.loadMappingTable(this.getMappingFile()); // Initialize and connect to JMS Queue JndiContextFactory jndiFactory = JndiContextFactory.newInstance(new Properties()); Context jndiCtx = jndiFactory.getJndiContext(); JMSManager jmsManager = JMSManager.newInstance(jndiCtx); QueueConnectionFactory connectionFactory = jmsManager.getQueueConnectionFactory(); connection = connectionFactory.createQueueConnection(); session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); // Create or get outgoing queue Queue queue = jmsManager.getQueue(this.getIncomingQueueName(), null); QueueReceiver receiver = session.createReceiver(queue); receiver.setMessageListener(this); // Start JMS Listener connection.start(); log.info("SMS Multiplexor Daemon has been started."); } catch (Exception e) { log.error("failure to initialize " + this.getClass().getCanonicalName(), e); } finally { } }
From source file:com.zotoh.maedr.device.JmsIO.java
private void inizQueue(Context ctx, Object obj) throws Exception { QueueConnectionFactory f = (QueueConnectionFactory) obj; final JmsIO me = this; QueueConnection conn;/*from w w w. j a v a 2 s. c om*/ Queue q = (Queue) ctx.lookup(_dest); if (!isEmpty(_jmsUser)) { conn = f.createQueueConnection(_jmsUser, _jmsPwd); } else { conn = f.createQueueConnection(); } _conn = conn; QueueSession s = conn.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); QueueReceiver r; r = s.createReceiver(q); r.setMessageListener(new MessageListener() { public void onMessage(Message msg) { me.onMessage(msg); } }); }