在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中,首先我配置了队列'jms/ queue /TestQ‘,并尝试部署相同的代码(在jboss 5.x中使用),它运行成功。我以为我必须创建'ActiveMQConnectionFactory‘对象并做进一步的事情,但事实并非如此。我在Jboss 5.x中使用的JMS在wildfly10中工作得很好。
JMS发送方和接收方部署在同一个wildfly实例上。我是否正确地实现了JMS队列功能?在wildfly10中这样做是正确的吗?如果没有,请将我引向链接/文档。
我的Que是我在Jboss 5.x (用于JMS队列实现)中使用的Java代码,不需要任何更改就可以在Wildfly-10中工作?
发布于 2017-05-22 13:14:10
对于Jboss 5.x,请转到JMS链接:
https://docs.jboss.org/jbossas/guides/j2eeguide/r2/en/html/ch6.chapt.html
https://stackoverflow.com/questions/43998780
复制相似问题