Keyword: ActiveMQ


ActiveMQ practice the road (four) ActiveMQ 4.x + JBoss 4.x MDP actual articles

At <<ActiveMQ实践之路(三) ActiveMQ 4.x +JBoss 4.x整合篇>> which we compare in detail the ActiveMQ with JBoss integration
Now that the selection JBoss, then the project will use more or less inside the EJB, the following we will introduce in detail how to ActiveMQ 4.x + JBOSS 4.x development environment
Message Driven Bean, and with the use of configuration jbossMQ made at a more detailed comparison. OrderMessage here is just a auto-generated Message Driven Bean, which in the onMessage method for log input.

1. Configure ejb-jar.xml

1. Ejb-jar.xml should not use XML DTD, required the use of XML Schema (XSD)
Many of my friends might use XDoclet to generate ejb-jar.xml, me here directly using XDoclet to generate the ejb-jar.xml are

<! - CTYPE ejb-jar PUBLIC "- / / Sun Microsystems, Inc. / / DTD Enterprise JavaBeans 2.0 / / EN" "http://java.sun.com/dtd/ejb-jar_2_0.dt-->

But in between ActiveMQ + JBoss configuration required to use the new XML Schema in order to complete the definition of ra, as follows.

xml code

  1. <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 direct use JBossMQ's Message DriverBean and use the difference between configuration ActiveMQ RA

(1). MessageDrivenBean use JBossMQ of the ejb-jar.xml configuration

xml code

  1. <! - Message Driven Beans ->
  2. <message-driven>
  3. <description>
  4. description>
  5. <display-name> Name for OrderMessagedisplay-name>
  6. <ejb-name> OrderMessageejb-name>
  7. <ejb-class> com.mostone.ejb.OrderMessageejb-class>
  8. <transaction-type> Containertransaction-type>
  9. <acknowledge-mode> Auto-acknowledgeacknowledge-mode>
  10. <message-driven-destination>
  11. <destination-type> javax.jms.Queuedestination-type>
  12. message-driven-destination>
  13. message-driven>


(2). The use of ActiveMQ RA configuration MessageDrivenBean the ejb-jar.xml configuration

xml code

  1. <! - Message Driven Beans ->
  2. <message-driven>
  3. <description>
  4. description>
  5. <display-name> Name for OrderMessagedisplay-name>
  6. <ejb-name> OrderMessageejb-name>
  7. <ejb-class> com.mostone.ejb.OrderMessageejb-class>
  8. <transaction-type> Containertransaction-type>
  9. <acknowledge-mode> Auto-acknowledgeacknowledge-mode>
  10. <! - Used activetion-config ->
  11. <activation-config>
  12. <activation-config-property>
  13. <activation-config-property-name> destinationactivation-config-property-name>
  14. <activation-config-property-value> queue.outboundactivation-config-property-value>
  15. activation-config-property>
  16. <activation-config-property>
  17. <activation-config-property-name> destinationTypeactivation-config-property-name>
  18. <activation-config-property-value> javax.jms.Queueactivation-config-property-value>
  19. activation-config-property>
  20. activation-config>
  21. message-driven>


One of destination, destinationType are provided configuration ra.xml inside the property, (here the official documents are Destination, DestinationType, and in fact activemq-ra.rar are ra.xml inside the destination, destinationType, pay attention to the difference between upper and lower case)

II. Jboss.xml configuration
Most configurations are at jboss.xml inside.
1. JBossMQ and use of the use of ActiveMQ RA configure Message Driven Bean distinction 1.) Use JBossMQ configuration

xml code

  1. <message-driven>
  2. <ejb-name> OrderMessageejb-name>
  3. <destination-jndi-name> queue / testQueuedestination-jndi-name>
  4. message-driven>


2.) Configuration using ActiveMQ RA

xml code

  1. <message-driven>
  2. <ejb-name> ActiveMQMDPejb-name>
  3. <! - The use of the resource-adapter-name ->
  4. <resource-adapter-name> activemq-ra.rarresource-adapter-name>
  5. <! - Here, the needs and configuration-name behind the container-name the name of the same ->
  6. <configuration-name> ActiveMQ Message Driven Beanconfiguration-name>
  7. message-driven>


2. Jboss.xml configuration invoker proxy and container to support the ActiveMQ RA

xml code

  1. <invoker-proxy-bindings>
  2. <invoker-proxy-binding>
  3. <name> activemq-message-driven-beanname>
  4. <invoker-mbean> defaultinvoker-mbean>
  5. <proxy-factory> org.jboss.ejb.plugins.inflow.JBossMessageEndpointFactoryproxy-factory>
  6. <proxy-factory-config>
  7. <endpoint-interceptors>
  8. <interceptor> org.jboss.proxy.ClientMethodInterceptorinterceptor>
  9. <interceptor> org.jboss.ejb.plugins.inflow.MessageEndpointInterceptorinterceptor>
  10. <interceptor> org.jboss.proxy.TransactionInterceptorinterceptor>
  11. <interceptor> org.jboss.invocation.InvokerInterceptorinterceptor>
  12. endpoint-interceptors>
  13. proxy-factory-config>
  14. invoker-proxy-binding>
  15. invoker-proxy-bindings>


MessageDrivenBean the container configuration, here must be the same as the above to work.



xml code

  1. <container-configurations>
  2. <container-configuration>
  3. <container-name> ActiveMQ Message Driven Beancontainer-name>
  4. <call-logging> falsecall-logging>
  5. <invoker-proxy-binding-name> activemq-message-driven-beaninvoker-proxy-binding-name>
  6. <container-interceptors>
  7. <interceptor> org.jboss.ejb.plugins.ProxyFactoryFinderInterceptorinterceptor>
  8. <interceptor> org.jboss.ejb.plugins.LogInterceptorinterceptor>
  9. <interceptor> org.jboss.ejb.plugins.RunAsSecurityInterceptorinterceptor>
  10. <! - CMT ->
  11. <interceptor transaction="Container"> org.jboss.ejb.plugins.TxInterceptorCMTinterceptor>
  12. <interceptor transaction="Container"> org.jboss.ejb.plugins.CallValidationInterceptorinterceptor>
  13. <interceptor transaction="Container" metricsEnabled="true"> org.jboss.ejb.plugins.MetricsInterceptorinterceptor>
  14. <interceptor transaction="Container"> org.jboss.ejb.plugins.MessageDrivenInstanceInterceptorinterceptor>
  15. <! - BMT ->
  16. <interceptor transaction="Bean"> org.jboss.ejb.plugins.MessageDrivenInstanceInterceptorinterceptor>
  17. <interceptor transaction="Bean"> org.jboss.ejb.plugins.MessageDrivenTxInterceptorBMTinterceptor>
  18. <interceptor transaction="Bean"> org.jboss.ejb.plugins.CallValidationInterceptorinterceptor>
  19. <interceptor transaction="Bean" metricsEnabled="true"> org.jboss.ejb.plugins.MetricsInterceptorinterceptor>
  20. <interceptor> org.jboss.resource.connectionmanager.CachedConnectionInterceptorinterceptor>
  21. container-interceptors>
  22. <instance-pool> org.jboss.ejb.plugins.MessageDrivenInstancePoolinstance-pool>
  23. <instance-cache> instance-cache>
  24. <persistence-manager> persistence-manager>
  25. <container-pool-conf>
  26. <MaximumSize> 100MaximumSize>
  27. container-pool-conf>
  28. container-configuration>
  29. container-configurations>


These are ActiveMQ + JBoss InBound configuration

Three. Medium at Servlet by sending a message to verify the above Message Driven Bean

In order to be able to verify this MessageDrivenBean normal job, I use a very simple servlet send a message to the queue, the former one of the activemq-ds.xml already provided at boot time bind the JNDI activemq / QueueConnectionFactory, activemq / queue / outbound, We used directly on the list,

java code

  1. try (
  2. initialContext = new InitialContext ();
  3. QueueConnectionFactory connectionFactory = (QueueConnectionFactory) initialContext
  4. . lookup ( "java: activemq / QueueConnectionFactory");
  5. Connection con = connectionFactory.createConnection ();
  6. Session session = con.createSession (false, Session.AUTO_ACKNOWLEDGE);
  7. Queue queue = (Queue) initialContext.lookup ( "activemq / queue / outbound");
  8. MessageProducer producer = session.createProducer (queue);
  9. TextMessage txtMessage = session.createTextMessage ();
  10. txtMessage.setText ( "A");
  11. producer.send (txtMessage);
  12. producer.close ();
  13. session.close ();
  14. con.close ();
  15. ) Catch (NamingException e) (
  16. / / TODO Auto-generated catch block
  17. e.printStackTrace ();
  18. ) Catch (JMSException e) (
  19. / / TODO Auto-generated catch block
  20. e.printStackTrace ();
  21. )


Iv. Topic about durable subscriptions to a supplementary explanation of the use of durable manner, you need at ejb-jar.xml in the extra configuration, subscriptionDurability, clientId, subscriptionName

xml code

  1. <activation-config>
  2. <activation-config-property>
  3. ......
  4. <activation-config-property>
  5. <activation-config-property-name> subscriptionDurabilityactivation-config-property-name>
  6. <activation-config-property-value> Durableactivation-config-property-value>
  7. activation-config-property>
  8. <activation-config-property>
  9. <activation-config-property-name> clientIdactivation-config-property-name>
  10. <activation-config-property-value> fooactivation-config-property-value>
  11. activation-config-property>
  12. <activation-config-property>
  13. <activation-config-property-name> subscriptionNameactivation-config-property-name>
  14. <activation-config-property-value> baractivation-config-property-value>
  15. activation-config-property>
  16. ......
  17. activation-config-property>
  18. activation-config>




ok so you can use durable subscriptions to a topic.

Reference documents:
JBoss Integration
ActiveMQ Inbound Communication
ActiveMQ Outbound Communication