JMS Api Demo
来源:互联网 发布:简述osi七层网络模型 编辑:程序博客网 时间:2024/06/06 03:09
jms.JMSFactory
jms.JMSMessageActor
jms.JMSMessageConsumer
- package jms;
- import javax.jms.TopicConnectionFactory;
- import org.apache.activemq.ActiveMQConnectionFactory;
- public class JMSFactory {
- private static ActiveMQConnectionFactory activeMQConnectionFactory =new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);
- public static TopicConnectionFactory getActiveMQConnectionFactory(){
- return activeMQConnectionFactory;
- }
- }
package jms;import javax.jms.TopicConnectionFactory;import org.apache.activemq.ActiveMQConnectionFactory;public class JMSFactory {private static ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(ActiveMQConnectionFactory.DEFAULT_BROKER_BIND_URL);public static TopicConnectionFactory getActiveMQConnectionFactory(){return activeMQConnectionFactory;}}
jms.JMSMessageActor
- package jms;
- import javax.jms.*;
- public abstract class JMSMessageActor {
- protected String name=null;
- protected String defaultQueueName="defalut-queue";
- protected String defaultTopicName="defalut-topic";
- protected final int DESTIONATION_TYPE_TOPIC=1;
- protected final int DESTIONATION_TYPE_QUEUE=2;
- public JMSMessageActor(String name) {
- this.name = name;
- }
- public abstract Destination getDestination();
- public Destination createDefaultDestination(int type){
- Destination dest=null;
- switch(type){
- case DESTIONATION_TYPE_TOPIC:
- dest=new Topic(){
- @Override
- public String getTopicName() throws JMSException {
- return defaultTopicName;
- }};break;
- case DESTIONATION_TYPE_QUEUE:
- dest=new Queue(){
- @Override
- public String getQueueName() throws JMSException {
- return defaultQueueName;
- }};
- break;
- }
- return dest;
- }
- }
package jms;import javax.jms.*;public abstract class JMSMessageActor {protected String name=null;protected String defaultQueueName="defalut-queue";protected String defaultTopicName="defalut-topic";protected final int DESTIONATION_TYPE_TOPIC=1;protected final int DESTIONATION_TYPE_QUEUE=2;public JMSMessageActor(String name) {this.name = name;}public abstract Destination getDestination();public Destination createDefaultDestination(int type){Destination dest=null;switch(type){case DESTIONATION_TYPE_TOPIC:dest=new Topic(){@Overridepublic String getTopicName() throws JMSException {return defaultTopicName;}};break;case DESTIONATION_TYPE_QUEUE:dest=new Queue(){@Overridepublic String getQueueName() throws JMSException {return defaultQueueName;}};break;}return dest;}}
jms.JMSMessageConsumer
- package jms;
- import javax.jms.*;
- public abstract class JMSMessageConsumer extends JMSMessageActorimplements Runnable,MessageListener{
- public JMSMessageConsumer(String name){
- super(name);
- }
- @Override
- public void onMessage(Message message) {
- synchronized(JMSMessageConsumer.class){
- System.out.println("##### consumer "+ name +" receive message. #####");
- System.out.println(JMSUtil.formatMessage(message));
- }
- }
- @Override
- public void run() {
- try{
- // get topic connect factory
- ConnectionFactory factory = JMSFactory.getActiveMQConnectionFactory();
- // create connection
- Connection connection = factory.createConnection();
- // create unique client id for the connection
- connection.setClientID("consumer_connection_"+name);
- // if the connection start method is not invoked , the consumer may be not receive the message
- connection.start();
- // create session
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Destination destination=getDestination();
- // if the destination is an instance of Queue ,
- // it will receive the message from the queue,
- // in other words the message can be consumed one time by one consumer
- // and the message is durable.
- // if the destination is an instance of Topic ,
- // the subscribers of the Topic can receive the message,
- // but the message is non durable.
- MessageConsumer consumer =session.createConsumer(destination,null,true);
- // if the destination is an instance of Topic,
- // specify the clientID of the connection
- // and create MessageConsumer like this,
- // the subscribers of the Topic can receive the message
- // and the message is durable.
- //consumer =session.createDurableSubscriber((Topic)destination, "durable topic", null, true);
- consumer.setMessageListener(this);
- }catch(Exception e){
- throw new RuntimeException(e);
- }
- }
- }
- JMS Api Demo
- JMS API
- JMS API-JMS API概述
- activemq: jms api实现queue和topic生产者、消费者demo及spring api 实现queue生产者、消费者
- JMS API编程模型
- JMS及其API介绍
- JMS + ActiveMQ 简单的demo
- JMS Activemq实战例子demo
- JMS规范和JMS中的API
- jms点对点API,发布/订阅API
- websphere mq jms调用通信demo
- JMS+spring中的简单应用(demo)
- SpringMVC+JMS(ActiveMQ)的小Demo
- JMS学习3 - JMS API的编程模型
- lehpone api demo学习
- API DEMO APPWIGHT 学习
- Google 翻译API Demo
- zookeeper api demo
- hashCode equal避免的几个误区
- Linux最小系统内核镜像文件的合成
- 深入阅读Mina源码(3) —— Mina之IOAdapter(一)
- Linux 最小内核bootsect学习与调试
- Java进程的JMX管理代理被禁用
- JMS Api Demo
- jQuery validate 用法
- java对象的存储
- 大整数相乘算法
- 重要的hashcode equals转载
- JAVA HashCode
- ERROR 1045 (28000): Access denied for user root@localhost (using password: NO)
- 常识知道的知识
- 错误: 找不到或无法加载主类