Search in sources :

Example 11 with MessageChannel

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));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) MessageHandler(org.springframework.messaging.MessageHandler) HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 12 with MessageChannel

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();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 13 with MessageChannel

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));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) MessageHandler(org.springframework.messaging.MessageHandler) DirectChannel(org.springframework.integration.channel.DirectChannel) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 14 with MessageChannel

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));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) MessageHandler(org.springframework.messaging.MessageHandler) DirectChannel(org.springframework.integration.channel.DirectChannel) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 15 with MessageChannel

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());
}
Also used : ExecutorSubscribableChannel(org.springframework.messaging.support.ExecutorSubscribableChannel) ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) TextMessage(org.springframework.web.socket.TextMessage) Message(org.springframework.messaging.Message) WebSocketMessage(org.springframework.web.socket.WebSocketMessage) BinaryMessage(org.springframework.web.socket.BinaryMessage) ImmutableMessageChannelInterceptor(org.springframework.messaging.support.ImmutableMessageChannelInterceptor) AtomicReference(java.util.concurrent.atomic.AtomicReference) MessageChannel(org.springframework.messaging.MessageChannel) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.Test)

Aggregations

MessageChannel (org.springframework.messaging.MessageChannel)20 Test (org.junit.Test)18 MessageHandler (org.springframework.messaging.MessageHandler)5 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)5 GenericMessage (org.springframework.messaging.support.GenericMessage)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 Message (org.springframework.messaging.Message)4 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)4 MessagingException (org.springframework.messaging.MessagingException)4 ExecutorSubscribableChannel (org.springframework.messaging.support.ExecutorSubscribableChannel)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 DirectChannel (org.springframework.integration.channel.DirectChannel)3 StubMessageChannel (org.springframework.messaging.StubMessageChannel)3 SubscribableChannel (org.springframework.messaging.SubscribableChannel)3 BinaryMessage (org.springframework.web.socket.BinaryMessage)3 TextMessage (org.springframework.web.socket.TextMessage)3 WebSocketMessage (org.springframework.web.socket.WebSocketMessage)3 HashMap (java.util.HashMap)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Exchange (org.apache.camel.Exchange)2