use of org.springframework.integration.MessageTimeoutException in project spring-integration by spring-projects.
the class PipelineNamedReplyQueuesJmsTests method test.
public int test(String contextConfig, final int offset) throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(contextConfig, this.getClass());
final AtomicInteger successCounter = new AtomicInteger();
final AtomicInteger timeoutCounter = new AtomicInteger();
final AtomicInteger failureCounter = new AtomicInteger();
try {
final RequestReplyExchanger gateway = context.getBean(RequestReplyExchanger.class);
final CountDownLatch latch = new CountDownLatch(requests);
for (int i = 1000000; i < 1000000 + requests * 100000; i += 100000) {
final int y = i;
executor.execute(() -> {
try {
assertEquals(y + offset, gateway.exchange(new GenericMessage<Integer>(y)).getPayload());
successCounter.incrementAndGet();
} catch (MessageTimeoutException e) {
timeoutCounter.incrementAndGet();
} catch (Throwable t) {
logger.error("gateway invocation failed", t);
failureCounter.incrementAndGet();
} finally {
latch.countDown();
}
});
}
assertTrue(latch.await(120, TimeUnit.SECONDS));
// technically all we care that its > 0,
// but reality of this test it has to be something more then 0
assertTrue(successCounter.get() > 1);
assertEquals(0, failureCounter.get());
assertEquals(requests, successCounter.get() + timeoutCounter.get());
return timeoutCounter.get();
} finally {
logger.info("Test config: " + contextConfig);
logger.info("Success: " + successCounter.get());
logger.info("Timeout: " + timeoutCounter.get());
logger.info("Failure: " + failureCounter.get());
if (timeoutCounter.get() > 0 && context.containsBean("capture")) {
logger.info(context.getBean(Capture.class).messages);
}
context.close();
}
}
use of org.springframework.integration.MessageTimeoutException in project spring-integration by spring-projects.
the class JmsOutboundGateway method handleRequestMessage.
@Override
protected Object handleRequestMessage(final Message<?> requestMessage) {
if (!this.initialized) {
afterPropertiesSet();
}
try {
Object reply;
if (this.replyContainer == null) {
reply = sendAndReceiveWithoutContainer(requestMessage);
} else {
if (this.idleReplyContainerTimeout > 0) {
synchronized (this.lifeCycleMonitor) {
this.lastSend = System.currentTimeMillis();
if (!this.replyContainer.isRunning()) {
if (logger.isDebugEnabled()) {
logger.debug(this.getComponentName() + ": Starting reply container.");
}
this.replyContainer.start();
this.idleTask = getTaskScheduler().scheduleAtFixedRate(new IdleContainerStopper(), this.idleReplyContainerTimeout / 2);
}
}
}
reply = this.sendAndReceiveWithContainer(requestMessage);
}
if (reply == null) {
if (this.requiresReply) {
throw new MessageTimeoutException(requestMessage, "failed to receive JMS response within timeout of: " + this.receiveTimeout + "ms");
} else {
return null;
}
}
if (reply instanceof javax.jms.Message) {
return buildReply((javax.jms.Message) reply);
} else {
return reply;
}
} catch (JMSException e) {
throw new MessageHandlingException(requestMessage, e);
}
}
Aggregations