我正在向主题发布 JMS 文本消息,并且消费者能够使用 (MDB) 文本消息。但无法获取消息对象和字符串属性。它在 MDB 消费者端为空。我在 META-INF 文件夹下的 ejb-jar.xml 中定义了 MDB。我在用
TomEE plus 7.0.2 JMS 2.0 IBM MQ 8 JDK 1.8 主题
我参考了下面提到的 Tomee 官方示例。例如,他们使用了 tomee.xml 而我使用了 resource.xml 并且不使用 web.xml
消费者是 MessageDrivenBean
消费者能够获得文本或对象消息。但 Message 属性为 null。
@Resource(name = "qcf")
private ConnectionFactory connectionFactory;
@Resource(name = "wmq-javax.jms.Topic")
private Topic topic;
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(topic);
TextMessage message = session.createTextMessage();
message.setText("Test Message");
message.setObjectProperty("a","b");
message.setStringProperty("c","D");
connection.start();
producer.send(message);
session.close();
connection.close();
消费者
<ejb-jar id="ejb-jar_ID" version="3.1"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
<display-name>SampleTransactionMDB</display-name>
<enterprise-beans>
<message-driven>
<display-name>SampleTransactionMDB</display-name>
<ejb-name>SampleTransactionMDB</ejb-name>
<ejb-class>com.example.SampleTransactionMDB</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>openejb:Resource/projectname/topicname</activation-config-property-value>
</activation-config-property>
</activation-config>
<activation-config-property>
<activation-config-property-name>useJNDI</activation-config-property-name>
<activation-config-property-value>true</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>HostName</activation-config-property-name>
<activation-config-property-value>x.x.x.x</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>Port</activation-config-property-name>
<activation-config-property-value>123</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>QueueManager</activation-config-property-name>
<activation-config-property-value>xxxxx</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>Channel</activation-config-property-name>
<activation-config-property-value>xxxx</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>TransportType</activation-config-property-name>
<activation-config-property-value>CLIENT</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>subscriptionName</activation-config-property-name>
<activation-config-property-value>xxxxxx</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>sharedSubscription</activation-config-property-name>
<activation-config-property-value>true</activation-config-property-value>
</activation-config-property>
</message-driven>
</enterprise-beans>
<assembly-descriptor>
</assembly-descriptor>
</ejb-jar>
指导我为什么消息属性在 MDB 使用者中为空。