use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class RequestReplyScenariosWithNonCachedConsumersTests method messageCorrelationBasedOnRequestCorrelationIdOptimized.
@Test
public void messageCorrelationBasedOnRequestCorrelationIdOptimized() throws Exception {
ActiveMqTestUtils.prepare();
AbstractApplicationContext context = new ClassPathXmlApplicationContext("producer-no-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("optimized", RequestReplyExchanger.class);
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueueA", Destination.class);
final Destination replyDestination = context.getBean("siInQueueA", Destination.class);
new Thread(() -> {
final Message requestMessage = jmsTemplate.receive(requestDestination);
jmsTemplate.send(replyDestination, (MessageCreator) session -> {
TextMessage message = session.createTextMessage();
message.setText("bar");
message.setJMSCorrelationID(requestMessage.getJMSCorrelationID());
return message;
});
}).start();
org.springframework.messaging.Message<?> siReplyMessage = gateway.exchange(new GenericMessage<String>("foo"));
assertEquals("bar", siReplyMessage.getPayload());
} finally {
context.close();
}
}
use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class RequestReplyScenariosWithNonCachedConsumersTests method messageCorrelationBasedOnRequestMessageIdOptimized.
@Test(expected = MessageTimeoutException.class)
public void messageCorrelationBasedOnRequestMessageIdOptimized() throws Exception {
ActiveMqTestUtils.prepare();
AbstractApplicationContext context = new ClassPathXmlApplicationContext("producer-no-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("optimizedMessageId", RequestReplyExchanger.class);
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueueC", Destination.class);
final Destination replyDestination = context.getBean("siInQueueC", Destination.class);
new Thread(() -> {
final Message requestMessage = jmsTemplate.receive(requestDestination);
jmsTemplate.send(replyDestination, (MessageCreator) session -> {
TextMessage message = session.createTextMessage();
message.setText("bar");
message.setJMSCorrelationID(requestMessage.getJMSMessageID());
return message;
});
}).start();
org.springframework.messaging.Message<?> siReplyMessage = gateway.exchange(new GenericMessage<String>("foo"));
assertEquals("bar", siReplyMessage.getPayload());
} finally {
context.close();
}
}
use of org.springframework.integration.gateway.RequestReplyExchanger 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.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class RequestReplyScenariosWithCorrelationKeyProvidedTests method messageCorrelationBasedOnProvidedJMSCorrelationID.
@Test
public void messageCorrelationBasedOnProvidedJMSCorrelationID() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("explicit-correlation-key.xml", this.getClass());
RequestReplyExchanger gateway = context.getBean("existingCorrelationKeyGatewayB", RequestReplyExchanger.class);
String correlationId = UUID.randomUUID().toString().replaceAll("'", "''");
Message<?> result = gateway.exchange(MessageBuilder.withPayload("foo").setHeader(JmsHeaders.CORRELATION_ID, correlationId).build());
assertEquals(correlationId, result.getHeaders().get("receivedCorrelationId"));
context.close();
}
use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class RequestReplyScenariosWithCorrelationKeyProvidedTests method messageCorrelationBasedCustomCorrelationKeyAsJMSCorrelationID.
@Test
public void messageCorrelationBasedCustomCorrelationKeyAsJMSCorrelationID() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("explicit-correlation-key.xml", this.getClass());
RequestReplyExchanger gateway = context.getBean("explicitCorrelationKeyGatewayB", RequestReplyExchanger.class);
gateway.exchange(MessageBuilder.withPayload("foo").build());
context.close();
}
Aggregations