use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class BroadcastingDispatcherTests method applySequenceEnabled.
@Test
public void applySequenceEnabled() {
BroadcastingDispatcher dispatcher = new BroadcastingDispatcher();
dispatcher.setApplySequence(true);
final List<Message<?>> messages = Collections.synchronizedList(new ArrayList<Message<?>>());
MessageHandler target1 = new MessageStoringTestEndpoint(messages);
MessageHandler target2 = new MessageStoringTestEndpoint(messages);
MessageHandler target3 = new MessageStoringTestEndpoint(messages);
dispatcher.addHandler(target1);
dispatcher.addHandler(target2);
dispatcher.addHandler(target3);
Message<?> inputMessage = new GenericMessage<String>("test");
Object originalId = inputMessage.getHeaders().getId();
dispatcher.dispatch(inputMessage);
assertEquals(3, messages.size());
assertEquals(1, new IntegrationMessageHeaderAccessor(messages.get(0)).getSequenceNumber());
assertEquals(3, new IntegrationMessageHeaderAccessor(messages.get(0)).getSequenceSize());
assertEquals(originalId, new IntegrationMessageHeaderAccessor(messages.get(0)).getCorrelationId());
assertEquals(2, new IntegrationMessageHeaderAccessor(messages.get(1)).getSequenceNumber());
assertEquals(3, new IntegrationMessageHeaderAccessor(messages.get(1)).getSequenceSize());
assertEquals(originalId, new IntegrationMessageHeaderAccessor(messages.get(1)).getCorrelationId());
assertEquals(3, new IntegrationMessageHeaderAccessor(messages.get(2)).getSequenceNumber());
assertEquals(3, new IntegrationMessageHeaderAccessor(messages.get(2)).getSequenceSize());
assertEquals(originalId, new IntegrationMessageHeaderAccessor(messages.get(2)).getCorrelationId());
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class UnicastingDispatcherTests method withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel.
@SuppressWarnings("unchecked")
@Test
public void withInboundGatewayAsyncRequestChannelAndExplicitErrorChannel() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("unicasting-with-async.xml", this.getClass());
SubscribableChannel errorChannel = context.getBean("errorChannel", SubscribableChannel.class);
MessageHandler errorHandler = message -> {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
assertTrue(message.getPayload() instanceof MessageDeliveryException);
replyChannel.send(new GenericMessage<String>("reply"));
};
errorChannel.subscribe(errorHandler);
RequestReplyExchanger exchanger = context.getBean(RequestReplyExchanger.class);
Message<String> reply = (Message<String>) exchanger.exchange(new GenericMessage<String>("Hello"));
assertEquals("reply", reply.getPayload());
context.close();
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class AsyncGatewayTests method listenableFutureWithMessageReturned.
@Test
public void listenableFutureWithMessageReturned() throws Exception {
QueueChannel requestChannel = new QueueChannel();
addThreadEnricher(requestChannel);
startResponder(requestChannel);
GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
proxyFactory.setDefaultRequestChannel(requestChannel);
proxyFactory.setServiceInterface(TestEchoService.class);
proxyFactory.setBeanName("testGateway");
proxyFactory.setBeanFactory(mock(BeanFactory.class));
proxyFactory.afterPropertiesSet();
TestEchoService service = (TestEchoService) proxyFactory.getObject();
ListenableFuture<Message<?>> f = service.returnMessageListenable("foo");
long start = System.currentTimeMillis();
final AtomicReference<Message<?>> result = new AtomicReference<Message<?>>();
final CountDownLatch latch = new CountDownLatch(1);
f.addCallback(new ListenableFutureCallback<Message<?>>() {
@Override
public void onSuccess(Message<?> msg) {
result.set(msg);
latch.countDown();
}
@Override
public void onFailure(Throwable t) {
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
long elapsed = System.currentTimeMillis() - start;
assertTrue(elapsed >= 200);
assertEquals("foobar", result.get().getPayload());
Object thread = result.get().getHeaders().get("thread");
assertNotEquals(Thread.currentThread(), thread);
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ObjectToMapTransformerParserTests method testObjectToSpelMapTransformer.
@SuppressWarnings("unchecked")
@Test
public void testObjectToSpelMapTransformer() {
Employee employee = this.buildEmployee();
StandardEvaluationContext context = new StandardEvaluationContext(employee);
context.addPropertyAccessor(new MapAccessor());
ExpressionParser parser = new SpelExpressionParser();
Message<Employee> message = MessageBuilder.withPayload(employee).build();
directInput.send(message);
Message<Map<String, Object>> outputMessage = (Message<Map<String, Object>>) output.receive();
Map<String, Object> transformedMap = outputMessage.getPayload();
assertNotNull(outputMessage.getPayload());
for (String key : transformedMap.keySet()) {
Expression expression = parser.parseExpression(key);
Object valueFromTheMap = transformedMap.get(key);
Object valueFromExpression = expression.getValue(context);
assertEquals(valueFromTheMap, valueFromExpression);
}
}
use of org.springframework.messaging.Message in project spring-integration by spring-projects.
the class ServiceActivatorMethodResolutionTests method testRequestReplyExchangerWithGenericMessageMethod.
@Test
public /*
* No handler fallback methods; don't force RRE
*/
void testRequestReplyExchangerWithGenericMessageMethod() {
RequestReplyExchanger testBean = new RequestReplyExchanger() {
@Override
public Message<?> exchange(Message<?> request) {
return request;
}
@SuppressWarnings("unused")
public String foo(Message<String> request) {
return request.getPayload().toUpperCase();
}
};
ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(testBean);
PollableChannel outputChannel = new QueueChannel();
serviceActivator.setOutputChannel(outputChannel);
Message<?> test = new GenericMessage<Object>(new Date());
serviceActivator.handleMessage(test);
assertEquals(test, outputChannel.receive(10));
test = new GenericMessage<Object>("foo");
serviceActivator.handleMessage(test);
assertEquals("FOO", outputChannel.receive(10).getPayload());
}
Aggregations