简体   繁体   中英

Trouble trying to consume persistent messages on Tibco EMS with selectors in Java (JMS)

So I'm trying to consume messages from a Tibco EMS broker via JMS with a message Id selector. If messages are NON_PERSISTENT, I can select them by their JMSMessageID's, and all works fine.

If the messages are PERSISTENT, the selector doesn't retrieve anything. I've tried the same code on Apache ActiveMQ, and it works in both cases. I've been through the EMS samples and cant see anything obvious. Wondering if there's some EMS settings that might affect this...

If I omit the selector, then messages are properly consumed regardless of DeliveryMode.

Here's what I'm using to reproduce it.

Any help would be much appreciated :)

package com;

import javax.jms.*;
import com.tibco.tibjms.TibjmsConnectionFactory;

public class JMSTest {
    String msgIdPersistent = "";
    String msgIdNon_Persistent = "";
    String serverUrl = "tcp://localhost:7222";
    String queueName = "test";

    public static void main(String[] args) {
        JMSTest test = new JMSTest();
        try {
            test.publish();
            test.deleteBySelector();
        }catch(Exception ex) {
            ex.printStackTrace();
        }
    }

    public void deleteBySelector() throws Exception {
        // Create connection and session
        ConnectionFactory factory = new TibjmsConnectionFactory(serverUrl);
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession();

        // Delete non-persistent
        //
        String selectorNonPersist  = "JMSMessageID='" + msgIdNon_Persistent + "'";
        MessageConsumer nonPersistReceiver = session.createConsumer(session.createQueue(queueName), selectorNonPersist);
        Message nonPersistMsg = null;
        nonPersistMsg = nonPersistReceiver.receive(1000);
        System.out.println("NON PERSISTENT SELECTOR:  " + ((nonPersistMsg!=null) ? "SUCCESS" : "FAIL"));

        // Delete Persistent - **** THIS DOESN'T WORK *****
        //
        String selectorPersist  = "JMSMessageID='" + msgIdPersistent + "'";
        MessageConsumer persistReceiver = session.createConsumer(session.createQueue(queueName), selectorPersist);
        Message persistMsg = null;
        persistMsg = persistReceiver.receive(1000);
        System.out.println("PERSISTENT SELECTOR:  " + ((persistMsg!=null) ? "SUCCESS" : "FAIL"));   
    }

    public void publish() throws Exception {
        ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(serverUrl);
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(javax.jms.Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue("test");

        // Send persistent message
        //
        System.out.println("Persistent publish");
        MessageProducer producerPersistent = session.createProducer(null);
        producerPersistent.setDeliveryMode(DeliveryMode.PERSISTENT);
        TextMessage messagePersistent = session.createTextMessage("PERSISTENT");
        producerPersistent.send(destination, messagePersistent);
        msgIdPersistent = messagePersistent.getJMSMessageID();
        System.out.println("\tMsgId=" + msgIdPersistent);

        // Send Non Persistent message
        //
        System.out.println("NON Persistent publish");
        MessageProducer producernonPersistent = session.createProducer(destination);
        producernonPersistent.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        TextMessage messageNonPersistent = session.createTextMessage("NON_PERSISTENT");
        producernonPersistent.send(messageNonPersistent);
        msgIdNon_Persistent = messageNonPersistent.getJMSMessageID();
        System.out.println("\tMsgId=" + msgIdNon_Persistent);

        // Clean up
        session.close();
        connection.close();

        System.out.println("Done publish\n");
    }
}

The output I'm getting from this is:

    Persistent publish
        MsgId=ID:EMS-SERVER.3D856ECE827932:1
    NON Persistent publish
        MsgId=ID:EMS-SERVER.3D856ECE827932:2
    Done publish

    NON PERSISTENT SELECTOR:  SUCCESS
    PERSISTENT SELECTOR:  FAIL

I've confirmed its a bug in 8.2.x. I upgraded to 8.3.x and it is working fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM