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();
}
}
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();
}
}
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();
}
}
Aggregations