1

我正在向主题发布 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

http://tomee.apache.org/tomee-and-webspheremq.html

@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 使用者中为空。

4

2 回答 2

1

I found the root cause of the problem. it is my mistake. TopicProxy's targetClient should be JMS. I wrongly configured as MQ. so I was able to get message but not property.

After changing targetClient value to JMS. I am able to get message and property

http://tomee.apache.org/tomee-and-webspheremq.html

于 2017-07-31T04:46:15.067 回答
0

MessageProducer 生产者 = session.createProducer(queue);

If you are publishing a message to topic then why are you using a variable named 'queue'? A topic string generally looks like 'test/ABC/one' (no quotes).

Secondly, why didn't you post the code for the consumer? Update your original posting to include the consumer code.

于 2017-07-26T16:31:22.053 回答