1

我正在使用 Stringboot、springboot starter artemis 和 camel

这是我对他们的依赖:

compile('org.springframework.boot:spring-boot-starter-artemis')

compile 'org.springframework:spring-jms'
compile 'org.apache.activemq:artemis-jms-client:1.5.6'
compile 'org.apache.activemq:artemis-jms-server:1.5.6'
// https://mvnrepository.com/artifact/org.apache.camel/camel-jms
compile group: 'org.apache.camel', name: 'camel-jms', version: '2.20.2'

这是我的代码(由于某种原因,我在这里没有使用 jms 模板)

  Connection connection = connectionFactory.createConnection();

            try {
                connection.setClientID(clientId);
                connection.start();

                //Create a JMS session
                Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);

                Topic topic = ActiveMQJMSClient.createTopic(processedHeaders.get(jmsdestination));
******JmsMessageUUID will dynamic, i have added JmsMessageUUID value = ID:142536687 as a example*********
                String selector = "JmsMessageUUID = 'ID:142536687'";
                //Create the subscription and the subscriber.
                MessageConsumer subscriber = session.createConsumer(topic,selector);

                //Consume the message from the durable subscription
                TextMessage messageReceived = (TextMessage) subscriber.receive();
                System.out.println("Received message: " + messageReceived.getText());
                // Acknowledge message
                messageReceived.acknowledge();
            }  finally {
                if (connection != null) {
                    // Close our JMS resources!
                    connection.close();
                } }
        }

我正在尝试使用 JmsMessageUUID 选择消息,它基本上是在发送消息期间设置的随机字符串,Jms 选择器无法找到消息,但是当我不使用选择器而不是成功使用消息时,我也检查了 jms 属性收到消息,并且 JmsMessageUUID 在具有相同字符串值的属性中可用。

我无法弄清楚为什么选择器不起作用?请在这里帮助我..

我还发现JMSMessageID过滤器适用于Queue但不适用于 Topoc:(

4

0 回答 0