use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class RequestReplyScenariosWithCachedConsumersTests method messageCorrelationBasedOnRequestCorrelationIdTimedOutFirstReplyOptimized.
@Test
public void messageCorrelationBasedOnRequestCorrelationIdTimedOutFirstReplyOptimized() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("producer-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("correlationPropagatingConsumerWithOptimizationDelayFirstReply", RequestReplyExchanger.class);
final ConnectionFactory connectionFactory = context.getBean("jmsConnectionFactory", ConnectionFactory.class);
final Destination requestDestination = context.getBean("siOutQueueE", Destination.class);
final Destination replyDestination = context.getBean("siInQueueE", Destination.class);
for (int i = 0; i < 3; i++) {
try {
gateway.exchange(gateway.exchange(new GenericMessage<String>("foo")));
} catch (Exception e) {
/*ignore*/
}
}
final CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> {
DefaultMessageListenerContainer dmlc = new DefaultMessageListenerContainer();
dmlc.setConnectionFactory(connectionFactory);
dmlc.setDestination(requestDestination);
dmlc.setMessageListener((SessionAwareMessageListener<Message>) (message, session) -> {
String requestPayload = (String) extractPayload(message);
try {
TextMessage replyMessage = session.createTextMessage();
replyMessage.setText(requestPayload);
replyMessage.setJMSCorrelationID(message.getJMSCorrelationID());
MessageProducer producer = session.createProducer(replyDestination);
producer.send(replyMessage);
} catch (Exception e) {
// ignore. the test will fail
}
});
dmlc.afterPropertiesSet();
dmlc.start();
latch.countDown();
}).start();
latch.await();
TestUtils.getPropertyValue(context.getBean("fastGateway"), "handler", JmsOutboundGateway.class).setReceiveTimeout(10000);
Thread.sleep(1000);
assertEquals("bar", gateway.exchange(new GenericMessage<String>("bar")).getPayload());
} finally {
context.close();
}
}
use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class RequestReplyScenariosWithCachedConsumersTests method messageCorrelationBasedOnRequestMessageIdNonOptimized.
@Test
public void messageCorrelationBasedOnRequestMessageIdNonOptimized() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("producer-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("standardMessageIdCopyingConsumerWithoutOptimization", RequestReplyExchanger.class);
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueueNonOptimizedB", Destination.class);
final Destination replyDestination = context.getBean("siInQueueNonOptimizedB", 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 RequestReplyScenariosWithCachedConsumersTests method messageCorrelationBasedOnRequestMessageIdOptimized.
@Test(expected = MessageTimeoutException.class)
public void messageCorrelationBasedOnRequestMessageIdOptimized() throws Exception {
ActiveMqTestUtils.prepare();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("producer-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("standardMessageIdCopyingConsumerWithOptimization", RequestReplyExchanger.class);
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueueOptimizedA", Destination.class);
final Destination replyDestination = context.getBean("siInQueueOptimizedA", 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();
gateway.exchange(new GenericMessage<String>("foo"));
} finally {
context.close();
}
}
use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class RequestReplyScenariosWithNonCachedConsumersTests method messageCorrelationBasedOnRequestCorrelationIdNonOptimized.
@Test(expected = MessageTimeoutException.class)
public void messageCorrelationBasedOnRequestCorrelationIdNonOptimized() throws Exception {
ActiveMqTestUtils.prepare();
AbstractApplicationContext context = new ClassPathXmlApplicationContext("producer-no-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("nonoptimized", RequestReplyExchanger.class);
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueueB", Destination.class);
final Destination replyDestination = context.getBean("siInQueueB", 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();
gateway.exchange(new GenericMessage<String>("foo"));
} finally {
context.close();
}
}
use of org.springframework.integration.gateway.RequestReplyExchanger in project spring-integration by spring-projects.
the class RequestReplyScenariosWithNonCachedConsumersTests method messageCorrelationBasedOnRequestMessageIdNonOptimized.
@Test
public void messageCorrelationBasedOnRequestMessageIdNonOptimized() throws Exception {
ActiveMqTestUtils.prepare();
AbstractApplicationContext context = new ClassPathXmlApplicationContext("producer-no-cached-consumers.xml", this.getClass());
try {
RequestReplyExchanger gateway = context.getBean("nonoptimizedMessageId", RequestReplyExchanger.class);
ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
final JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
final Destination requestDestination = context.getBean("siOutQueueD", Destination.class);
final Destination replyDestination = context.getBean("siInQueueD", 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();
}
}
Aggregations