文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>使用EJB_JMS

使用EJB_JMS

时间:2007-01-01  来源:liulibo

1.Queue
 QueueConnectionFactory factory = (QueueConnectionFactory)ic.lookup("factory");
 QueueConnection conn = factory.createQueueConnection();
 QueueSession session = conn.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
 
 Queue queue = (Queue)ic.lookup("queue");
 创建发送队列
 QueueSender sender = session.createSender(queue);
 创建消息
 TextMessage message = session.createTextMessage("zhanghao");
 发送消息
 sender.send(message);

 

 创建接收队列
 QueueReceiver receiver = session.createReceiver(queue);
 开始接收消息
 conn.start();
 接收消息
 TextMessage mes = (TextMessage)receiver.receive();
 打印消息
 System.out.println(mes.getText());
2.Topic
 MessageListener接口public void onMessage(Message message)方法监听消息
 
 TopicConnectionFactory factory = (TopicConnectionFactory)ic.lookup("factory");
 TopicConnection conn = factory.createTopicConnection();
 TopicSession session = conn.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
 
 Topic topic = (Topic)ic.lookup("topic");
 创建发布主题
 TopicPublisher pub = session.createPublisher(topic);
 创建消息
 TextMessage message = session.createTextMessage("zhanghao");
 发布消息
 pub.publish(message);
 
 创建订户主题
 TopicSubscriber sub = session.createSubscriber(topic);
 开始接收消息
 conn.start();
 接收消息
 TextMessage mes = (TextMessage)receiver.receive();
 
3.Durable_Topic
 设置ID
 conn.setClientID(name);
 创建持久订户主题
 TopicSubscriber sub = session.createDurableSubscriber(topic,"abc");
 开始接收消息
 conn.start();
 接收消息
 TextMessage mes = (TextMessage)receiver.receive();
 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载