use of javax.jms.Destination 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();
}
}
use of javax.jms.Destination in project rocketmq-externals by apache.
the class SimpleExMessageListenerContainer method createListenerConsumer.
/**
* Create a MessageConsumer for the given JMS Session, registering a
* MessageListener for the specified listener.
*
* @param session
* the JMS Session to work on
*
* @return the MessageConsumer
*
* @throws JMSException
* if thrown by JMS methods
* @see #executeListener
*/
protected MessageConsumer createListenerConsumer(final Session session) throws JMSException {
Destination destination = getDestination();
if (destination == null) {
destination = resolveDestinationName(session, getDestinationName());
}
MessageConsumer consumer = createConsumer(session, destination);
consumer.setMessageListener((MessageListener) super.getMessageListener());
return consumer;
}
use of javax.jms.Destination in project wso2-axis2-transports by wso2.
the class JMSSenderTestCase method testIsWaitForResponseOrReplyDestinationWhenOneIsTrue.
public void testIsWaitForResponseOrReplyDestinationWhenOneIsTrue() throws Exception {
JMSSender jmsSender = new JMSSender();
boolean result1 = jmsSender.isWaitForResponseOrReplyDestination(true, null);
Assert.assertTrue(assertErrorMessageForTrue, result1);
Destination destination = Mockito.mock(Destination.class);
boolean result2 = jmsSender.isWaitForResponseOrReplyDestination(false, destination);
Assert.assertTrue(assertErrorMessageForTrue, result2);
}
use of javax.jms.Destination in project wso2-axis2-transports by wso2.
the class JMSSenderTestCase method testIsWaitForResponseOrReplyDestinationBothTrue.
public void testIsWaitForResponseOrReplyDestinationBothTrue() throws Exception {
JMSSender jmsSender = new JMSSender();
Destination destination = Mockito.mock(Destination.class);
boolean result = jmsSender.isWaitForResponseOrReplyDestination(true, destination);
Assert.assertTrue(assertErrorMessageForTrue, result);
}
use of javax.jms.Destination in project wso2-axis2-transports by wso2.
the class MockEchoEndpoint method setUp.
@Setup
@SuppressWarnings("unused")
private void setUp(JMSTestEnvironment env, JMSRequestResponseChannel channel) throws Exception {
Destination destination = channel.getDestination();
Destination replyDestination = channel.getReplyDestination();
connection = env.getConnectionFactory().createConnection();
connection.setExceptionListener(this);
connection.start();
replyConnection = env.getConnectionFactory().createConnection();
replyConnection.setExceptionListener(this);
final Session replySession = replyConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageProducer producer = replySession.createProducer(replyDestination);
MessageConsumer consumer = connection.createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
public void onMessage(Message message) {
try {
log.info("Message received: ID = " + message.getJMSMessageID());
Message reply;
if (message instanceof BytesMessage) {
reply = replySession.createBytesMessage();
IOUtils.copy(new BytesMessageInputStream((BytesMessage) message), new BytesMessageOutputStream((BytesMessage) reply));
} else if (message instanceof TextMessage) {
reply = replySession.createTextMessage();
((TextMessage) reply).setText(((TextMessage) message).getText());
} else {
// TODO
throw new UnsupportedOperationException("Unsupported message type");
}
reply.setJMSCorrelationID(message.getJMSMessageID());
reply.setStringProperty(BaseConstants.CONTENT_TYPE, message.getStringProperty(BaseConstants.CONTENT_TYPE));
producer.send(reply);
log.info("Message sent: ID = " + reply.getJMSMessageID());
} catch (Throwable ex) {
fireEndpointError(ex);
}
}
});
}
Aggregations