Message Driven Bean(MDB): 消息驱动Bean,基于JMS
1.JMS介绍
JMS是java的消息服务,JMS的客户端之间可以通过JMS服务进行异步的消息传输。JMS支持两种消息模型,Point-toPoint(P2P)和Publish/Subscribe(Pub/Sub),即点对点和发布订阅模型
运行的状态:当然,为了缓和这种严格的时间相关性,JMS允许订阅者创建一个可持久化的订阅。这样,即使订阅者没有被激活(运行),它也能接收到发布者的消息。 如果你希望发送的消息可以不被做任何处理、或者被一个消费者处理、或者可以被多个消费者处理的话,那么可以采用Pub/Sub模型
消息的消费:在JMS中,消息的产生和消费是异步的。对于消息来说,JMS的消费者可以通过两种方式 来消费消息。
同步:订阅者或接受者调用receive方法来接受消息,receive方法在能够接收到消息之前(超时之前)将一直阻塞
异步:订阅者或接受者可以注册为一个消息监听器。当消息到达之后,系统自动调用监听器的onMessage方法
2.JMS编程模型
Connection Factory
创建Cooection对象的工厂,针对两种不同的JMS消息模型,分别有QueueConnectionFactory和TopicConnectionFactory两种。可以通过JNDI来查找ConnectionFactory的对象。
Destination
Destination的意思是消息生产者的消息发送目标或者说是消息消费者的消息来源,对于消息生产者来说,它的Destination是某个队列(Queue)或某个主题(Topic),对于消息消费者来说,它的Destination也是某个队列或主题(即消息来源)。所以,Destination实际上就是两种类型的对象——Queue,Topic。可以通过JNDI来查找Destination
Conneciton
Connection表示客户端和JMS系统之间建立的链接(对TCP/IP socket 的包装)。Connection可以产生一个或多个Session。跟ConnectionFactory一样,Connection也有两种QueueConnection和TopicConnection。
Session
Session使我们操作消息的接口,可以通过session创建生产者、消费者、消息等。Session提供了事务的功能。当我们需要使用session发送/接受多个消息时,可以将这些发送/接受动作放到一个事务中。同样,也分QueueSession和 TopicSession。
消息消费者
消息消费者由Session创建。用于接受被发送到Destination的消息,QueueReceiver和TopicSubscriber,可分别通过session的createReceiver(queue)或createSubscriber(topic)来创建,当然,也可以通过 session的createDurableSubscriber方法来创建持久化的订阅者。
MessageListener
消息监听器,如果注册了消息监听器,一旦消息到达,将自动调用监听器的onMessage方法。EJB中的MDB(Message Driver Bean)就是一种MessageListener。
3.MDB介绍
对于客户端来说,message-driven bean 就是异步消息的消费者。当消息到达之后,由容器负责调用MDB。客户端发送消息到destination,MDB作为一个MessageListener接受消息
Saturday, June 13, 2009
Saturday, February 21, 2009
Friday, February 13, 2009
Installing Eclipse: Some of my Favourite Plug-ins
http://java.dzone.com/articles/installing-eclipse-some-my
I just reinstalled a fresh version of Eclipse onto my workstation. I switch between IDEs a fair bit, depending on what I am doing. Eclipse is great for Maven work, mainly because of the m2eclipse plugin that just keeps getting better and better. IntelliJ, on the other hand, is king when it comes to Groovy and Grails. Here, I will run through how I typically set up my Eclipse environment. So, here is the procedure:
I just reinstalled a fresh version of Eclipse onto my workstation. I switch between IDEs a fair bit, depending on what I am doing. Eclipse is great for Maven work, mainly because of the m2eclipse plugin that just keeps getting better and better. IntelliJ, on the other hand, is king when it comes to Groovy and Grails. Here, I will run through how I typically set up my Eclipse environment. So, here is the procedure:
- Download the latest Eclipse EE package (in this case, Ganymede SR1).
- Update the pre-installed plugins to the latest version.
- Install Subclipse (http://subclipse.tigris.org/update_1.4.x) - very cool support for Subversion 1.5 branching and merging.
- I skip the AJDT plugin, as I don't use AspectJ for my current projects. If you are, you might want to include this one to benefit from the maven-aspectj-plugin integration.
- Install M2Eclipse (http://m2eclipse.sonatype.org/update-dev/) - note this is the dev snapshot - I like living dangerously ;-).
I'm a big fan of code quality and code metrics, so I add the standard code quality-related plugins:
- Checkstyle (http://eclipse-cs.sourceforge.net/update)
- PMD (http://pmd.sourceforge.net/eclipse)
- FindBugs (http://findbugs.cs.umd.edu/eclipse/)
- ECLEmma (http://update.eclemma.org/) - nice light-weight code coverage from within Eclipse
- (and/or) Clover (http://update.atlassian.com/eclipse/clover) - if you are serious about code coverage ;-)
I do occasionally do some work in Groovy in Eclipse (though IntelliJ is nicer on this front), so I add some Groovy support:
- Groovy Eclipse plugin (http://dist.codehaus.org/groovy/distributions/update/)
I like to monitor my CI servers from within my IDE. For Hudson, I use this one:
- Hudson Eclipse plugin (http//hudson-eclipse.googlecode.com/svn/trunk/hudson-update/)
I'm not adverse to a bit of commercial software, if it improves my productivity and doesn't require me to take out another mortgage. So I may well install the following commercial plugins:
- JUnitMax (the tool is still a bit rough in parts, but those unit test failures marked with red crosses, just like compilation failures, really are quite addictive).
- Tasktop (sort of like Mylyn on steroids)
With this, I have an operational development environment. I might install others as the need arises, but this gets me up and running in Eclipse with a minimum of fuss.
Subscribe to:
Comments (Atom)