ActiveMQ 实践之路(四) ActiveMQ 4.x +JBoss 4.x MDP实战篇
在<<ActiveMQ 实践之路(三) ActiveMQ 4.x +JBoss 4.x 整合篇 >>里面我们比较详细的讲解了ActiveMQ与JBoss的整合,
既然选择了JBoss,那么项目里面或多或少都会使用到EJB,下面我们就详细地介绍如何在ActiveMQ 4.x+JBOSS 4.x环境下开发
Message Driven Bean,并且与使用jbossMQ在配置上作了比较详细地比较。这里的OrderMessage 仅仅是一个自动生成的Message Driven Bean,在onMessage方法里面,作日志输入。
一. 配置ejb-jar.xml
1. ejb-jar.xml 不能使用XML DTD,需要使用XML Schema(XSD)
很多朋友可能使用XDoclet来生成ejb-jar.xml,我这里直接使用XDoclet生成的ejb-jar.xml是
<!---->
但是在ActiveMQ+JBoss配置中间需要使用新的XML Schema才能完成对ra的定义,如下.
xml 代码
- <ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1">
2. ejb-jar.xml 直接使用JBossMQ的Message DriverBean 和使用ActiveMQ RA配置的区别
(1) .使用JBossMQ的MessageDrivenBean的 ejb-jar.xml配置
xml 代码
-
- <message-driven>
- <description>
-
- description>
- <display-name>Name for OrderMessagedisplay-name>
- <ejb-name>OrderMessageejb-name>
- <ejb-class>com.mostone.ejb.OrderMessageejb-class>
- <transaction-type>Containertransaction-type>
- <acknowledge-mode>Auto-acknowledgeacknowledge-mode>
- <message-driven-destination>
- <destination-type>javax.jms.Queuedestination-type>
- message-driven-destination>
- message-driven>
(2). 使用ActiveMQ RA配置的MessageDrivenBean的ejb-jar.xml配置
xml 代码
-
- <message-driven>
- <description>
-
- description>
- <display-name>Name for OrderMessagedisplay-name>
- <ejb-name>OrderMessageejb-name>
- <ejb-class>com.mostone.ejb.OrderMessageejb-class>
- <transaction-type>Containertransaction-type>
- <acknowledge-mode>Auto-acknowledgeacknowledge-mode>
-
- <activation-config>
- <activation-config-property>
- <activation-config-property-name>destinationactivation-config-property-name>
- <activation-config-property-value>queue.outboundactivation-config-property-value>
- activation-config-property>
- <activation-config-property>
- <activation-config-property-name>destinationTypeactivation-config-property-name>
- <activation-config-property-value>javax.jms.Queueactivation-config-property-value>
- activation-config-property>
- activation-config>
- message-driven>
其中destination,destinationType是ra.xml里面提供的配置属性,(这里官方的文档是Destination,DestinationType, 而实际上activemq-ra.rar里面的ra.xml是destination,destinationType,注意大小写区别)
二. 配置jboss.xml
大部分配置都是在jboss.xml里面.
1.使用JBossMQ 和使用ActiveMQ RA配置Message Driven Bean的区别
1.) 使用JBossMQ 的配置
xml 代码
- <message-driven>
- <ejb-name>OrderMessageejb-name>
- <destination-jndi-name>queue/testQueuedestination-jndi-name>
- message-driven>
2.) 使用ActiveMQ RA的配置
xml 代码
- <message-driven>
- <ejb-name>ActiveMQMDPejb-name>
-
- <resource-adapter-name>activemq-ra.rarresource-adapter-name>
-
- <configuration-name>ActiveMQ Message Driven Beanconfiguration-name>
- message-driven>
2. jboss.xml 配置invoker proxy和container 支持ActiveMQ RA
xml 代码
- <invoker-proxy-bindings>
- <invoker-proxy-binding>
- <name>activemq-message-driven-beanname>
- <invoker-mbean>defaultinvoker-mbean>
- <proxy-factory>org.jboss.ejb.plugins.inflow.JBossMessageEndpointFactoryproxy-factory>
- <proxy-factory-config>
- <endpoint-interceptors>
- <interceptor>org.jboss.proxy.ClientMethodInterceptorinterceptor>
- <interceptor>org.jboss.ejb.plugins.inflow.MessageEndpointInterceptorinterceptor>
- <interceptor>org.jboss.proxy.TransactionInterceptorinterceptor>
- <interceptor>org.jboss.invocation.InvokerInterceptorinterceptor>
- endpoint-interceptors>
- proxy-factory-config>
- invoker-proxy-binding>
- invoker-proxy-bindings>
MessageDrivenBean的container配置,这里的<container-name></container-name>必须和上面的<configuration-name></configuration-name>相同 才能起作用.
xml 代码
- <container-configurations>
- <container-configuration>
- <container-name>ActiveMQ Message Driven Beancontainer-name>
- <call-logging>falsecall-logging>
- <invoker-proxy-binding-name>activemq-message-driven-beaninvoker-proxy-binding-name>
- <container-interceptors>
- <interceptor>org.jboss.ejb.plugins.ProxyFactoryFinderInterceptorinterceptor>
- <interceptor>org.jboss.ejb.plugins.LogInterceptorinterceptor>
- <interceptor>org.jboss.ejb.plugins.RunAsSecurityInterceptorinterceptor>
-
- <interceptor transaction="Container">org.jboss.ejb.plugins.TxInterceptorCMTinterceptor>
- <interceptor transaction="Container">org.jboss.ejb.plugins.CallValidationInterceptorinterceptor>
- <interceptor transaction="Container" metricsEnabled="true">org.jboss.ejb.plugins.MetricsInterceptorinterceptor>
- <interceptor transaction="Container">org.jboss.ejb.plugins.MessageDrivenInstanceInterceptorinterceptor>
-
- <interceptor transaction="Bean">org.jboss.ejb.plugins.MessageDrivenInstanceInterceptorinterceptor>
- <interceptor transaction="Bean">org.jboss.ejb.plugins.MessageDrivenTxInterceptorBMTinterceptor>
- <interceptor transaction="Bean">org.jboss.ejb.plugins.CallValidationInterceptorinterceptor>
- <interceptor transaction="Bean" metricsEnabled="true">org.jboss.ejb.plugins.MetricsInterceptorinterceptor>
- <interceptor>org.jboss.resource.connectionmanager.CachedConnectionInterceptorinterceptor>
- container-interceptors>
- <instance-pool>org.jboss.ejb.plugins.MessageDrivenInstancePoolinstance-pool>
- <instance-cache>instance-cache>
- <persistence-manager>persistence-manager>
- <container-pool-conf>
- <MaximumSize>100MaximumSize>
- container-pool-conf>
- container-configuration>
- container-configurations>
以上就是ActiveMQ+JBoss InBound 的配置
三.在Servlet中通过发送消息,验证上面的Message Driven Bean
为了验证这个MessageDrivenBean能够正常工作,我使用一个很简单的servlet向这个queue发送消息,前一篇的activemq-ds.xml 已经提供在启动的时候绑定了JNDI activemq/QueueConnectionFactory,activemq/queue/outbound,我们直接使用就行了,
java 代码
- try {
- initialContext = new InitialContext();
- QueueConnectionFactory connectionFactory = (QueueConnectionFactory) initialContext
- .lookup("java:activemq/QueueConnectionFactory");
- Connection con=connectionFactory.createConnection();
- Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- Queue queue = (Queue) initialContext.lookup("activemq/queue/outbound");
- MessageProducer producer = session.createProducer(queue);
- TextMessage txtMessage = session.createTextMessage();
- txtMessage.setText("A");
- producer.send(txtMessage);
- producer.close();
- session.close();
- con.close();
-
- } catch (NamingException e) {
-
- e.printStackTrace();
- } catch (JMSException e) {
-
- e.printStackTrace();
- }
四.关于durable方式订阅topic的补充说明
使用durable方式,你需要在ejb-jar.xml中额外的配置,subscriptionDurability,clientId,subscriptionName
xml 代码
- <activation-config>
- <activation-config-property>
- ......
- <activation-config-property>
- <activation-config-property-name>subscriptionDurabilityactivation-config-property-name>
- <activation-config-property-value>Durableactivation-config-property-value>
- activation-config-property>
- <activation-config-property>
- <activation-config-property-name>clientIdactivation-config-property-name>
- <activation-config-property-value>fooactivation-config-property-value>
- activation-config-property>
- <activation-config-property>
- <activation-config-property-name>subscriptionNameactivation-config-property-name>
- <activation-config-property-value>baractivation-config-property-value>
- activation-config-property>
- ......
- activation-config-property>
- activation-config>
ok 这样就可以使用durable方式订阅topic了。
参考文档:
JBoss Integration
ActiveMQ Inbound Communication
ActiveMQ Outbound Communication
分享到:
- 2007-03-09 23:02
- 浏览 5357
- 评论(0)
- 论坛回复 / 浏览 (0 / 6788)
- 查看更多
相关推荐
apache-activemq-5.16.6-bin.zip
Apache ActiveMQ是Apache软件基金会的一个开源项目,是一个基于消息的通信中间件。ActiveMQ是JMS的一个具体实现,支持JMS的两种消息模型。ActiveMQ使用AMQP协议集成多平台应用,使用STOMP协议通过websockets在Web...
MQ是消息中间件,是一种在分布式系统中应用程序借以传递消息的媒介,常用的有ActiveMQ,RabbitMQ,kafka。ActiveMQ是Apache下的开源项目,完全支持JMS1.1和J2EE1.4规范的JMS Provider实现。 特点: 1、支持多种...
标签:activemq-ra-4.1.1.jar.zip,activemq,ra,4.1.1,jar.zip包下载,依赖包
1、介绍ActiveMQ5.x消息队列基础特性和本地快速安装 2、SpringBoot2.x整合ActiveMQ实战之点对点消息
4.配置环境变量,配置完环境变量之后在任何地方都可以使用命令 activemq启动 ACTIVEMQ_HOME=/opt/apache-activemq-5.15.12 PATH=/opt/apache-activemq-5.15.12/bin:$PATH export ACTIVEMQ_HOME PATH 5....
activemq-all.5.14jar包,亲测可用!!
activemq实战
支持jdk1.7_80的activeMQ可在Linux环境解压部署,可以参考我的博客
ActiveMQ实践入门指南
springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot +netty+activeMq在线客服系统springboot...
demo...springmvc+dubbo/zookeeper+activemq+redis+mybatis+druid
ActiveMQ 5.15.11 Linux版,
ActiveMQ_实践之路(一)ActiveMQ_实践之路(二)ActiveMQ_实践之路(三)ActiveMQ_实践之路(四)
apache-activemq-5.16.0.zip
apache-activemq-5.12.0-bin.tar.gz.
apache-activemq-5.3.1-bin.tar.gz安装包,apache-activemq-5.3.1版本安装包
ActiveMQ 实践之路(一) 启动你的ActiveMQ 程度: 入门 一.安装ActiveMQ 首先去http://activemq.apache.org/download.html 下载最新版本4.1.0release (http://activemq.apache.org/activemq-410-release.html), ...
apache-activemq-5.15.3-bin.tar.gz