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