Wilfly10 apache artemis - JMS实现

时间:2017-05-16 10:21:53

标签: jms activemq wildfly-10

在Jboss 5.x中,JMS模型队列(点到点)过去实现如下(MDB类和ejb-jar.xml)

MDB

package receiver;
import javax.jms.JMSException;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import javax.jms.Message;
public class WildFlyJmsQueueReceiveLocal  implements MessageListener {
public void onMessage(Message msg) {
 try {
     System.out.println("[WildFlyJmsQueueReceiveLocal][onMessage]There are three kinds of basic JMS connection-factory that depends on the type of connectors that is used.");          
   String msgText;
       if (msg instanceof TextMessage) {
          msgText = ((TextMessage)msg).getText();
       } else {
          msgText = msg.toString();
       }
       if (msgText.equalsIgnoreCase("quit")) {
         synchronized(this) {
             this.notifyAll(); // Notify main thread to quit
         }
       }           
  } catch (JMSException | InterruptedException jmse) {
      jmse.printStackTrace();
 }
}
}

ejb-jar.xml中

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<display-name>MDB</display-name>
<enterprise-beans>
<message-driven>
 <display-name>MDB1</display-name>
 <ejb-name>MDB1</ejb-name>
 <ejb-class>receiver.WildFlyJmsQueueReceiveLocal</ejb-class>
 <transaction-type>Container</transaction-type>
 <activation-config>
    <activation-config-property>
        <activation-config-property-name>destinationType</activation-config-property-name>
        <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
        <activation-config-property-name>destination</activation-config-property-name>
        <activation-config-property-value>jms/queue/TestQ</activation-config-property-value>
    </activation-config-property>
    <activation-config-property>
    <activation-config-property-name>maxSession</activation-config-property-name>
   <activation-config-property-value>2</activation-config-property-value>
    </activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
</ejb-jar>

现在我从jboss 5.x迁移到wildfly10。在wildfly 10中,使用“Apache ActiveMQ Artemis”实现了JMS功能。 所以在wildfly 10中,我首先配置了队列&#39; jms / queue / TestQ&#39;并尝试部署相同的代码(在jboss 5.x中使用),它运行成功。我以为我必须创建&#39; ActiveMQConnectionFactory&#39;对象并做更多的东西,但它不是那样的。我在Jboss 5.x中使用的JMS API在wildfly10中运行良好。

JMS发送方和接收方部署在同一个wildfly实例上。我正确实现了JMS队列功能吗?这是在wildfly10中做的正确方法吗?如果没有,请指导我链接/文档。

我的阙是 我在Jboss 5.x中使用的Java代码(用于JMS-Queue实现)可以在Wildfly-10中使用而不做任何更改?

1 个答案:

答案 0 :(得分:1)