use of javax.jms.MessageConsumer in project pinpoint by naver.
the class ActiveMQClientITBase method testQueuePull.
@Test
public void testQueuePull() throws Exception {
// Given
final String testQueueName = "TestPullQueue";
final ActiveMQQueue testQueue = new ActiveMQQueue(testQueueName);
final String testMessage = "Hello World for Queue!";
// create producer
ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
MessageProducer producer = producerSession.createProducer(testQueue);
final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
// When
ActiveMQSession consumerSession = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
MessageConsumer consumer = consumerSession.createConsumer(testQueue);
// Then
producer.send(expectedTextMessage);
Message message = consumer.receive(1000L);
Assert.assertEquals(testMessage, ((TextMessage) message).getText());
// Wait till all traces are recorded (consumer traces are recorded from another thread)
awaitAndVerifyTraceCount(5, 5000L);
// trace count : 1
verifyProducerSendEvent(testQueue);
// trace count : 4
verifyConsumerPullEvent(testQueue, consumer, expectedTextMessage);
}
use of javax.jms.MessageConsumer in project pinpoint by naver.
the class MessageConsumerBuilder method build.
public MessageConsumer build() throws Exception {
MessageConsumer consumer = null;
if (waitTillStarted) {
ConsumerEventSource consumerEventSource = new ConsumerEventSource(session.getConnection(), destination);
final CountDownLatch latch = new CountDownLatch(1);
consumerEventSource.setConsumerListener(new ConsumerListener() {
@Override
public void onConsumerEvent(ConsumerEvent event) {
latch.countDown();
}
});
try {
consumerEventSource.start();
consumer = this.session.createConsumer(this.destination);
if (!latch.await(5L, TimeUnit.SECONDS)) {
throw new TimeoutException("Timed out waiting for MessageConsumer start event.");
}
} finally {
consumerEventSource.stop();
}
} else {
consumer = this.session.createConsumer(this.destination);
}
if (this.messageListener != null) {
consumer.setMessageListener(this.messageListener);
}
return consumer;
}
use of javax.jms.MessageConsumer in project spring-framework by spring-projects.
the class JmsInvokerClientInterceptor method doExecuteRequest.
/**
* Actually execute the given request, sending the invoker request message
* to the specified target queue and waiting for a corresponding response.
* <p>The default implementation is based on standard JMS send/receive,
* using a {@link javax.jms.TemporaryQueue} for receiving the response.
* @param session the JMS Session to use
* @param queue the resolved target Queue to send to
* @param requestMessage the JMS Message to send
* @return the RemoteInvocationResult object
* @throws JMSException in case of JMS failure
*/
protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException {
TemporaryQueue responseQueue = null;
MessageProducer producer = null;
MessageConsumer consumer = null;
try {
responseQueue = session.createTemporaryQueue();
producer = session.createProducer(queue);
consumer = session.createConsumer(responseQueue);
requestMessage.setJMSReplyTo(responseQueue);
producer.send(requestMessage);
long timeout = getReceiveTimeout();
return (timeout > 0 ? consumer.receive(timeout) : consumer.receive());
} finally {
JmsUtils.closeMessageConsumer(consumer);
JmsUtils.closeMessageProducer(producer);
if (responseQueue != null) {
responseQueue.delete();
}
}
}
use of javax.jms.MessageConsumer in project spring-framework by spring-projects.
the class SimpleMessageListenerContainer method doShutdown.
/**
* Destroy the registered JMS Sessions and associated MessageConsumers.
*/
@Override
protected void doShutdown() throws JMSException {
synchronized (this.consumersMonitor) {
if (this.consumers != null) {
logger.debug("Closing JMS MessageConsumers");
for (MessageConsumer consumer : this.consumers) {
JmsUtils.closeMessageConsumer(consumer);
}
logger.debug("Closing JMS Sessions");
for (Session session : this.sessions) {
JmsUtils.closeSession(session);
}
}
}
}
use of javax.jms.MessageConsumer in project spring-framework by spring-projects.
the class SimpleMessageListenerContainerTests method testContextRefreshedEventStartsTheConnectionByDefault.
@Test
public void testContextRefreshedEventStartsTheConnectionByDefault() throws Exception {
MessageConsumer messageConsumer = mock(MessageConsumer.class);
Session session = mock(Session.class);
// Queue gets created in order to create MessageConsumer for that Destination...
given(session.createQueue(DESTINATION_NAME)).willReturn(QUEUE_DESTINATION);
// and then the MessageConsumer gets created...
// no MessageSelector...
given(session.createConsumer(QUEUE_DESTINATION, null)).willReturn(messageConsumer);
Connection connection = mock(Connection.class);
// session gets created in order to register MessageListener...
given(connection.createSession(this.container.isSessionTransacted(), this.container.getSessionAcknowledgeMode())).willReturn(session);
// and the connection is start()ed after the listener is registered...
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
given(connectionFactory.createConnection()).willReturn(connection);
this.container.setConnectionFactory(connectionFactory);
this.container.setDestinationName(DESTINATION_NAME);
this.container.setMessageListener(new TestMessageListener());
this.container.afterPropertiesSet();
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton("messageListenerContainer", this.container);
context.refresh();
verify(connection).setExceptionListener(this.container);
verify(connection).start();
}
Aggregations