Search in sources :

Example 1 with JmsBaseMessageConsumer

use of org.apache.rocketmq.jms.domain.JmsBaseMessageConsumer in project rocketmq-externals by apache.

the class JmsConsumerIT method testStartIdempotency.

@Test
public void testStartIdempotency() throws Exception {
    JmsBaseConnectionFactory connectionFactory = new JmsBaseConnectionFactory(new URI("rocketmq://xxx?consumerId=" + consumerId + "&nameServer=" + nameServer));
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    checkConsumerState(consumerId, true, false);
    try {
        Destination destination = session.createTopic(topic + ":" + messageType);
        MessageConsumer consumer = session.createConsumer(destination);
        consumer.setMessageListener(listener);
        checkConsumerState(consumerId, false, false);
        ((JmsBaseMessageConsumer) consumer).startConsumer();
        checkConsumerState(consumerId, false, true);
        Destination destination1 = session.createTopic(topic2 + ":" + messageType);
        MessageConsumer consumer1 = session.createConsumer(destination1);
        consumer1.setMessageListener(listener);
        ((JmsBaseMessageConsumer) consumer1).startConsumer();
        checkConsumerState(consumerId, false, true);
        // the start is idempotent
        connection.start();
        connection.start();
        Thread.sleep(5000);
    } finally {
        connection.close();
    }
}
Also used : Destination(javax.jms.Destination) JmsBaseMessageConsumer(org.apache.rocketmq.jms.domain.JmsBaseMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) JmsBaseMessageConsumer(org.apache.rocketmq.jms.domain.JmsBaseMessageConsumer) JmsBaseConnectionFactory(org.apache.rocketmq.jms.domain.JmsBaseConnectionFactory) Connection(javax.jms.Connection) URI(java.net.URI) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

URI (java.net.URI)1 Connection (javax.jms.Connection)1 Destination (javax.jms.Destination)1 MessageConsumer (javax.jms.MessageConsumer)1 Session (javax.jms.Session)1 JmsBaseConnectionFactory (org.apache.rocketmq.jms.domain.JmsBaseConnectionFactory)1 JmsBaseMessageConsumer (org.apache.rocketmq.jms.domain.JmsBaseMessageConsumer)1 Test (org.junit.Test)1