Search in sources :

Example 1 with JmsBaseConnectionFactory

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

the class JmsClientIT method testConfigInURI.

@Test
public void testConfigInURI() throws Exception {
    JmsBaseConnectionFactory connectionFactory = new JmsBaseConnectionFactory(new URI(String.format("rocketmq://xxx?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s", CommonConstant.PRODUCERID, producerId, CommonConstant.CONSUMERID, consumerId, CommonConstant.NAMESERVER, nameServer, CommonConstant.CONSUME_THREAD_NUMS, consumeThreadNums, CommonConstant.SEND_TIMEOUT_MILLIS, 10 * 1000, CommonConstant.INSTANCE_NAME, "JMS_TEST")));
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    connection.start();
    try {
        Destination destination = session.createTopic(topic + ":" + messageType);
        session.createConsumer(destination);
        session.createProducer(destination);
        DefaultMQPushConsumer rmqPushConsumer = (DefaultMQPushConsumer) getRMQPushConsumerExt(consumerId).getConsumer();
        Assert.assertNotNull(rmqPushConsumer);
        Assert.assertEquals(consumerId, rmqPushConsumer.getConsumerGroup());
        Assert.assertEquals("JMS_TEST", rmqPushConsumer.getInstanceName());
        Assert.assertEquals(consumeThreadNums, rmqPushConsumer.getConsumeThreadMax());
        Assert.assertEquals(consumeThreadNums, rmqPushConsumer.getConsumeThreadMin());
        Assert.assertEquals(nameServer, rmqPushConsumer.getNamesrvAddr());
        DefaultMQProducer mqProducer = (DefaultMQProducer) JmsTestUtil.getMQProducer(producerId);
        Assert.assertNotNull(mqProducer);
        Assert.assertEquals(producerId, mqProducer.getProducerGroup());
        Assert.assertEquals("JMS_TEST", mqProducer.getInstanceName());
        Assert.assertEquals(10 * 1000, mqProducer.getSendMsgTimeout());
        Assert.assertEquals(nameServer, mqProducer.getNamesrvAddr());
        Thread.sleep(2000);
    } finally {
        connection.close();
    }
}
Also used : Destination(javax.jms.Destination) JmsBaseConnectionFactory(org.apache.rocketmq.jms.domain.JmsBaseConnectionFactory) Connection(javax.jms.Connection) DefaultMQPushConsumer(org.apache.rocketmq.client.consumer.DefaultMQPushConsumer) URI(java.net.URI) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) Session(javax.jms.Session) Test(org.junit.Test)

Example 2 with JmsBaseConnectionFactory

use of org.apache.rocketmq.jms.domain.JmsBaseConnectionFactory 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)

Example 3 with JmsBaseConnectionFactory

use of org.apache.rocketmq.jms.domain.JmsBaseConnectionFactory 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)

Aggregations

URI (java.net.URI)3 Connection (javax.jms.Connection)3 Destination (javax.jms.Destination)3 Session (javax.jms.Session)3 JmsBaseConnectionFactory (org.apache.rocketmq.jms.domain.JmsBaseConnectionFactory)3 Test (org.junit.Test)3 MessageConsumer (javax.jms.MessageConsumer)2 JmsBaseMessageConsumer (org.apache.rocketmq.jms.domain.JmsBaseMessageConsumer)2 DefaultMQPushConsumer (org.apache.rocketmq.client.consumer.DefaultMQPushConsumer)1 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)1 JmsTestUtil.getRMQPushConsumerExt (org.apache.rocketmq.jms.JmsTestUtil.getRMQPushConsumerExt)1 RMQPushConsumerExt (org.apache.rocketmq.jms.domain.RMQPushConsumerExt)1