Search in sources :

Example 1 with RMQPushConsumerExt

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

the class JmsTestUtil method checkConsumerState.

public static void checkConsumerState(String consumerId, boolean isNull, boolean isStarted) throws Exception {
    RMQPushConsumerExt rmqPushConsumerExt = getRMQPushConsumerExt(consumerId);
    if (isNull) {
        Assert.assertNull(rmqPushConsumerExt);
    } else {
        Assert.assertNotNull(rmqPushConsumerExt);
        Assert.assertEquals(isStarted, rmqPushConsumerExt.isStarted());
    }
}
Also used : RMQPushConsumerExt(org.apache.rocketmq.jms.domain.RMQPushConsumerExt)

Example 2 with RMQPushConsumerExt

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

the class JmsConsumerIT method testReferenceCount.

@Test
public void testReferenceCount() 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);
    connection.start();
    try {
        Destination destination = session.createTopic(topic + ":" + messageType);
        MessageConsumer consumer = session.createConsumer(destination);
        consumer.setMessageListener(listener);
        RMQPushConsumerExt rmqPushConsumerExt = getRMQPushConsumerExt(consumerId);
        Assert.assertNotNull(rmqPushConsumerExt);
        Assert.assertEquals(1, rmqPushConsumerExt.getReferenceCount());
        MessageConsumer consumer2 = session.createConsumer(destination);
        Assert.assertEquals(2, rmqPushConsumerExt.getReferenceCount());
        MessageConsumer consumer3 = session.createConsumer(session.createTopic(topic + ":" + messageType));
        Assert.assertEquals(3, rmqPushConsumerExt.getReferenceCount());
        session.close();
        Assert.assertEquals(0, rmqPushConsumerExt.getReferenceCount());
        Assert.assertEquals(false, rmqPushConsumerExt.isStarted());
        Assert.assertNull(getRMQPushConsumerExt(consumerId));
        Thread.sleep(5000);
    } finally {
        connection.close();
    }
}
Also used : Destination(javax.jms.Destination) JmsBaseMessageConsumer(org.apache.rocketmq.jms.domain.JmsBaseMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) JmsTestUtil.getRMQPushConsumerExt(org.apache.rocketmq.jms.JmsTestUtil.getRMQPushConsumerExt) RMQPushConsumerExt(org.apache.rocketmq.jms.domain.RMQPushConsumerExt) JmsBaseConnectionFactory(org.apache.rocketmq.jms.domain.JmsBaseConnectionFactory) Connection(javax.jms.Connection) URI(java.net.URI) Session(javax.jms.Session) Test(org.junit.Test)

Example 3 with RMQPushConsumerExt

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

the class JmsTestUtil method getRMQPushConsumerExt.

public static RMQPushConsumerExt getRMQPushConsumerExt(String consumerId) throws Exception {
    Assert.assertNotNull(consumerId);
    Field field = JmsBaseMessageConsumer.class.getDeclaredField("consumerMap");
    field.setAccessible(true);
    ConcurrentMap<String, RMQPushConsumerExt> consumerMap = (ConcurrentMap<String, RMQPushConsumerExt>) field.get(null);
    return consumerMap.get(consumerId);
}
Also used : Field(java.lang.reflect.Field) RMQPushConsumerExt(org.apache.rocketmq.jms.domain.RMQPushConsumerExt) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

RMQPushConsumerExt (org.apache.rocketmq.jms.domain.RMQPushConsumerExt)3 Field (java.lang.reflect.Field)1 URI (java.net.URI)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Connection (javax.jms.Connection)1 Destination (javax.jms.Destination)1 MessageConsumer (javax.jms.MessageConsumer)1 Session (javax.jms.Session)1 JmsTestUtil.getRMQPushConsumerExt (org.apache.rocketmq.jms.JmsTestUtil.getRMQPushConsumerExt)1 JmsBaseConnectionFactory (org.apache.rocketmq.jms.domain.JmsBaseConnectionFactory)1 JmsBaseMessageConsumer (org.apache.rocketmq.jms.domain.JmsBaseMessageConsumer)1 Test (org.junit.Test)1