use of org.springframework.messaging.MessageChannel in project camel by apache.
the class SpringIntegrationTwoWayConsumerTest method testSendingTwoWayMessage.
@Test
public void testSendingTwoWayMessage() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
MessageChannel requestChannel = getMandatoryBean(MessageChannel.class, "requestChannel");
Map<String, Object> maps = new HashMap<String, Object>();
maps.put(MessageHeaders.REPLY_CHANNEL, "responseChannel");
Message<String> message = new GenericMessage<String>(MESSAGE_BODY, maps);
DirectChannel responseChannel = getMandatoryBean(DirectChannel.class, "responseChannel");
responseChannel.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message) {
latch.countDown();
assertEquals("Get the wrong result", MESSAGE_BODY + " is processed", message.getPayload());
assertEquals("Done", message.getHeaders().get("Status"));
}
});
requestChannel.send(message);
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of org.springframework.messaging.MessageChannel in project camel by apache.
the class CamelTargetAdapterTest method testSendingOneWayMessage.
@Test
public void testSendingOneWayMessage() throws Exception {
MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);
MessageChannel outputChannel = getMandatoryBean(MessageChannel.class, "channelA");
outputChannel.send(new GenericMessage<Object>(MESSAGE_BODY));
assertMockEndpointsSatisfied();
}
use of org.springframework.messaging.MessageChannel in project camel by apache.
the class CamelTargetAdapterTest method testSendingTwoWayMessage.
@Test
public void testSendingTwoWayMessage() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
MessageChannel requestChannel = getMandatoryBean(MessageChannel.class, "channelB");
Message<?> message = new GenericMessage<Object>(MESSAGE_BODY);
//Need to subscribe the responseChannel first
DirectChannel responseChannel = getMandatoryBean(DirectChannel.class, "channelC");
responseChannel.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message) {
latch.countDown();
assertEquals("Get the wrong result", MESSAGE_BODY + " is processed", message.getPayload());
}
});
requestChannel.send(message);
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of org.springframework.messaging.MessageChannel in project camel by apache.
the class CamelTargetAdapterTest method testSendingTwoWayMessageWithMessageAddress.
@Test
public void testSendingTwoWayMessageWithMessageAddress() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
MessageChannel requestChannel = getMandatoryBean(MessageChannel.class, "channelD");
DirectChannel responseChannel = getMandatoryBean(DirectChannel.class, "channelC");
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(MessageHeaders.REPLY_CHANNEL, responseChannel);
GenericMessage<String> message = new GenericMessage<String>(MESSAGE_BODY, headers);
responseChannel.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message) {
latch.countDown();
assertEquals("Get the wrong result", MESSAGE_BODY + " is processed", message.getPayload());
}
});
requestChannel.send(message);
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of org.springframework.messaging.MessageChannel in project spring-framework by spring-projects.
the class StompSubProtocolHandlerTests method handleMessageFromClientWithImmutableMessageInterceptor.
@Test
public void handleMessageFromClientWithImmutableMessageInterceptor() {
AtomicReference<Boolean> mutable = new AtomicReference<>();
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
channel.addInterceptor(new ChannelInterceptorAdapter() {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
mutable.set(MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class).isMutable());
return message;
}
});
channel.addInterceptor(new ImmutableMessageChannelInterceptor());
StompSubProtocolHandler handler = new StompSubProtocolHandler();
handler.afterSessionStarted(this.session, channel);
TextMessage message = StompTextMessageBuilder.create(StompCommand.CONNECT).build();
handler.handleMessageFromClient(this.session, message, channel);
assertNotNull(mutable.get());
assertTrue(mutable.get());
}
Aggregations