JMS

  Most of the communications between components that you have seen so far are synchronous: one class calls another, a managed bean invokes an EJB, which calls an entity, and so on. 

   Message-oriented middleware (MOM) is software (a provider) that enables asynchronous 

messages between heterogeneous systems. It can be seen as a buffer between systems that 

produce and consume messages at their own pace

    JMS is a standard Java API that allows applications to create, send, receive, and read messages 

asynchronously

--

就跟我们在计算机系统中常提到的生产者与消费者一样.消费者,生产者不需要互相知道对方的存在.as long as the sender and receiver agree on the message format and the intermediate 

SUBJECT:

    how to connect to a provider, create different types of messages, send them to 

queues or topics, and receive them all or filter them with selectors


两种模式:

p2p communication

pub-sub communication

不同的模式下 destination connectionFactory分别有不同的支持,实现不同的接口,由不同的模式下的connectionFactory 分别可以创建不同模式下的 connection ,session......

consumer

provider

administered object -->:

Destination

• javax.jms.Queue objects used for P2P communication

 • javax.jms.Topic objects used for pub-sub communication

ConnectionFactory (可注入)➥

 • javax.jms.ConnectionFactoryis an interface than can be used for both P2P and pubsub communications.

 • javax.jms.QueueConnectionFactoryis an interface that extends ConnectionFactoryand 

is used for P2P communication.

 • javax.jms.TopicConnectionFactoryis an interface that extends ConnectionFactoryand is used for pub-sub communication

QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) ctx.lookup("QConnFactory");

TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) ctx.lookup("TConnFactory");

ConnectionFactory ConnectionFactory = (QueueConnectionFactory) ctx.lookup("GenericConnFactory");

    connection 线程安全的,可共享 ➥

    Connection connection = connFactory.createConnection();

    QueueConnection connection = queueConnFactory.createQueueConnection();

    TopicConnection connection = topicConnFactory.createTopicConnection();

        session 单线程 ,支持事务/非事务➥

            Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);

            //true:支持事务,AUTO_ACKNOWLEDGE,消息被接收后会自动通知.

            Message :分装消息,以三部分发送到destination

             //Structure of a JMS message,太长,不写了.

            Messageproducer

            发送message.

            pub-sub model-->publisher

            P2P-->sender

            MessageConsumer

            可以选择是异步或者同步的接收消息.

            异步的话需要实现MessageListener 接口,回调方法onMessage.

            Selectors

            包含过滤条件的字符串(based on a subset of the SQL92),过滤消息.

            在message的header中设置一些属性:

            message.setIntProperty("orderAmount", 1530);

            接收:

            session.createConsumer(topic, "JMSPriority < 6");


在容器中使用MessageDriverBean中开发JMS还是很简单的.




--<<beginning javaee6 with glassFish 3>>

--基于JMS 和MOM 的信息交换系统研究

-----------------------------------------------------------

Using Distributed Destinations:

http://docs.oracle.com/cd/E13222_01/wls/docs100/jms/dds.html  

http://www.javalobby.org/articles/distributed-jms/ 

 在注解中配置JNDI属性用到的:

http://docs.oracle.com/cd/E18930_01/html/821-2416/gbtvg.html#gkkwq 


转载于:https://my.oschina.net/fuckmylife0/blog/317062

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值