【发布时间】:2017-10-15 09:03:06
【问题描述】:
在 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 中,JMS 功能已使用“Apache ActiveMQ Artemis”实现。 所以在wildfly 10中,首先我配置了队列'jms/queue/TestQ'并尝试部署相同的代码(在jboss 5.x中使用),它运行成功。我以为我必须创建“ActiveMQConnectionFactory”对象并做更多的事情,但事实并非如此。我在 Jboss 5.x 中使用的 JMS API 在 wildfly10 中运行良好。
JMS 发送器和接收器部署在同一个 Wildfly 实例上。我是否正确实现了 JMS 队列功能?这是在wildfly10中做的正确方法吗?如果没有,请引导我访问链接/文档。
我的问题是 我在 Jboss 5.x 中使用的 Java 代码(用于 JMS-Queue 实现)将在 Wildfly-10 中工作而无需任何更改?
【问题讨论】:
-
请回复...
-
同样的代码也可以。你是如何发送消息的?当您的发件人发送消息时,它是否被添加到队列中?您可以在
admin-console上查看。检查Messages Added的天气计数是否增加了您的队列。如果不是,请与您的发件人联系。
标签: jms activemq wildfly-10