日期:2014-05-16 浏览次数:20715 次
import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.TextMessage; /** * @author Jamson Huang * */ @MessageDriven( activationConfig={ @ActivationConfigProperty(propertyName="destinationType",propertyValue="javax.jms.Queue"), @ActivationConfigProperty(propertyName="destination",propertyValue="queue/QueueMdb") } ) /*P2P*/ public class QueueMdbBean implements MessageListener { /* (non-Javadoc) * @see javax.jms.MessageListener#onMessage(javax.jms.Message) */ public void onMessage(Message msg) { try{ TextMessage txtMsg = (TextMessage)msg; System.out.println("Queue Text:"+ txtMsg.getText()); }catch(Exception ex){ ex.printStackTrace(); } } }
import javax.jms.Queue; import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; import javax.jms.QueueSender; import javax.jms.QueueSession; import javax.jms.TextMessage; import javax.naming.InitialContext; /** * @author Jamson Huang * */ public class QueueMdbEjbBeanClient { /** * @param args */ public static void main(String[] args) throws Exception { InitialContext context = new InitialContext(); QueueConnectionFactory factory = (QueueConnectionFactory)context.lookup("ConnectionFactory"); QueueConnection conn = factory.createQueueConnection(); QueueSession session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE); Queue queue = (Queue)context.lookup("queue/QueueMdb"); TextMessage txtMsg = session.createTextMessage("Hello world, Jamson"); QueueSender sender = session.createSender(queue); sender.send(txtMsg); System.out.println(txtMsg.getText()); session.close(); conn.close(); System.out.println("queue has been sent!"); } } }
import javax.ejb.ActivationConfigProperty; import javax.ejb.MessageDriven; import javax.jms.Message; import javax.jms.MessageListener; import javax.jms.TextMessage; /** * @author Jamson Huang * */ @MessageDriven( activationConfig={ @ActivationConfigProperty(propertyName="destinationType",propertyValue="javax.jms.Topic"), @ActivationConfigProperty(propertyName="destination",propertyValue="topic/TopicMdb") } ) public class TopicMdbBean implements MessageListener { /* (non-Javadoc) * @see javax.jms.MessageListener#onMessage(javax.jms.Message) */ public void onMessage(Message msg) { // TODO Auto-generated method stub try{ TextMessage txtMsg = (TextMessage)msg; System.out.println("Queue Text:"+ txtMsg.getText()); }catch(Exception ex){ ex.printStackTrace(); } } }
import javax.jms.TextMessage; import javax.jms.Topic; import javax.jms.TopicConnection; import javax.jms.TopicConnectionFactory; import javax.jms.TopicPublisher; import javax.jms.TopicSession; import javax.naming.InitialContext; /** * @author Jamson Huang * */ public class TopicMdbEjbBeanClient { /** * @param args */ public static void main(String[] args) throws Exception { InitialContext context = new InitialContext(); TopicConnectionFactory factory = (TopicConnectionFactory)context.lookup("ConnectionFactory"); TopicConnection conn = factory.createTopicConnection(); TopicSession session = conn.createTopicSess