Search in sources :

Example 6 with GenericMessage

use of org.springframework.messaging.support.GenericMessage 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 7 with GenericMessage

use of org.springframework.messaging.support.GenericMessage 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 8 with GenericMessage

use of org.springframework.messaging.support.GenericMessage 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 9 with GenericMessage

use of org.springframework.messaging.support.GenericMessage in project spring-framework by spring-projects.

the class MessageReceivingTemplateTests method receiveAndConvertFailed.

@Test
public void receiveAndConvertFailed() {
    Message<?> expected = new GenericMessage<Object>("not a number test");
    this.template.setReceiveMessage(expected);
    this.template.setMessageConverter(new GenericMessageConverter());
    thrown.expect(MessageConversionException.class);
    thrown.expectCause(isA(ConversionFailedException.class));
    this.template.receiveAndConvert("somewhere", Integer.class);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) GenericMessageConverter(org.springframework.messaging.converter.GenericMessageConverter) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) Test(org.junit.Test)

Aggregations

GenericMessage (org.springframework.messaging.support.GenericMessage)9 Test (org.junit.Test)8 MessageChannel (org.springframework.messaging.MessageChannel)5 MessageHandler (org.springframework.messaging.MessageHandler)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 DirectChannel (org.springframework.integration.channel.DirectChannel)3 HashMap (java.util.HashMap)2 MessagingException (org.springframework.messaging.MessagingException)2 StubMessageChannel (org.springframework.messaging.StubMessageChannel)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 GenericMessageConverter (org.springframework.messaging.converter.GenericMessageConverter)2 ExecutorSubscribableChannel (org.springframework.messaging.support.ExecutorSubscribableChannel)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Converter (org.apache.camel.Converter)1 SpringIntegrationMessage (org.apache.camel.component.spring.integration.SpringIntegrationMessage)1 MethodParameter (org.springframework.core.MethodParameter)1 ConversionFailedException (org.springframework.core.convert.ConversionFailedException)1 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)1 MessageHeaders (org.springframework.messaging.MessageHeaders)1 MessageConversionException (org.springframework.messaging.converter.MessageConversionException)1