Search in sources :

Example 96 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class ChainParserTests method chainNestingAndAggregation.

@SuppressWarnings("rawtypes")
@Test
public void chainNestingAndAggregation() throws Exception {
    Message<?> message = MessageBuilder.withPayload("test").setCorrelationId(1).setSequenceSize(1).build();
    this.aggregatorInput.send(message);
    Message reply = this.output.receive(3000);
    assertNotNull(reply);
    assertEquals("foo", reply.getPayload());
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Test(org.junit.Test)

Example 97 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class ChannelInterceptorTests method testPostReceiveInterceptor.

@Test
public void testPostReceiveInterceptor() {
    final AtomicInteger invokedCount = new AtomicInteger();
    final AtomicInteger messageCount = new AtomicInteger();
    channel.addInterceptor(new ChannelInterceptorAdapter() {

        @Override
        public Message<?> postReceive(Message<?> message, MessageChannel channel) {
            assertNotNull(channel);
            assertSame(ChannelInterceptorTests.this.channel, channel);
            if (message != null) {
                messageCount.incrementAndGet();
            }
            invokedCount.incrementAndGet();
            return message;
        }
    });
    channel.receive(0);
    assertEquals(1, invokedCount.get());
    assertEquals(0, messageCount.get());
    channel.send(new GenericMessage<String>("test"));
    Message<?> result = channel.receive(0);
    assertNotNull(result);
    assertEquals(2, invokedCount.get());
    assertEquals(1, messageCount.get());
}
Also used : ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 98 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class ChannelInterceptorTests method afterCompletionWithSendException.

@Test
public void afterCompletionWithSendException() {
    final AbstractMessageChannel testChannel = new AbstractMessageChannel() {

        @Override
        protected boolean doSend(Message<?> message, long timeout) {
            throw new RuntimeException("Simulated exception");
        }
    };
    AfterCompletionTestInterceptor interceptor1 = new AfterCompletionTestInterceptor();
    AfterCompletionTestInterceptor interceptor2 = new AfterCompletionTestInterceptor();
    testChannel.addInterceptor(interceptor1);
    testChannel.addInterceptor(interceptor2);
    try {
        testChannel.send(MessageBuilder.withPayload("test").build());
    } catch (Exception ex) {
        assertEquals("Simulated exception", ex.getCause().getMessage());
    }
    assertTrue(interceptor1.wasAfterCompletionInvoked());
    assertTrue(interceptor2.wasAfterCompletionInvoked());
}
Also used : AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Test(org.junit.Test)

Example 99 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class ResequencingMessageGroupProcessorTests method shouldProcessSequence.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void shouldProcessSequence() {
    Message prototypeMessage = MessageBuilder.withPayload("foo").setCorrelationId("x").setSequenceNumber(1).setSequenceSize(3).build();
    List<Message<?>> messages = new ArrayList<Message<?>>();
    Message message1 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(1).build();
    Message message2 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(2).build();
    Message message3 = MessageBuilder.fromMessage(prototypeMessage).setSequenceNumber(3).build();
    messages.add(message1);
    messages.add(message2);
    messages.add(message3);
    SimpleMessageGroup group = new SimpleMessageGroup(messages, "x");
    List<Message> processedMessages = (List<Message>) processor.processMessageGroup(group);
    assertThat(processedMessages, hasItems(message1, message2, message3));
}
Also used : Message(org.springframework.messaging.Message) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) Test(org.junit.Test)

Example 100 with Message

use of org.springframework.messaging.Message in project spring-integration by spring-projects.

the class DirectChannelSubscriptionTests method exceptionThrownFromRegisteredEndpoint.

@Test(expected = MessagingException.class)
public void exceptionThrownFromRegisteredEndpoint() {
    AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {

        @Override
        public Object handleRequestMessage(Message<?> message) {
            throw new RuntimeException("intentional test failure");
        }
    };
    handler.setOutputChannel(targetChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(sourceChannel, handler);
    context.registerEndpoint("testEndpoint", endpoint);
    context.refresh();
    try {
        this.sourceChannel.send(new GenericMessage<String>("foo"));
    } finally {
        context.stop();
    }
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) Test(org.junit.Test)

Aggregations

Message (org.springframework.messaging.Message)597 Test (org.junit.Test)423 GenericMessage (org.springframework.messaging.support.GenericMessage)272 QueueChannel (org.springframework.integration.channel.QueueChannel)189 MessageChannel (org.springframework.messaging.MessageChannel)128 ArrayList (java.util.ArrayList)113 BeanFactory (org.springframework.beans.factory.BeanFactory)85 CountDownLatch (java.util.concurrent.CountDownLatch)80 DirectChannel (org.springframework.integration.channel.DirectChannel)69 AtomicReference (java.util.concurrent.atomic.AtomicReference)68 Test (org.junit.jupiter.api.Test)65 MessageHandler (org.springframework.messaging.MessageHandler)58 List (java.util.List)56 PollableChannel (org.springframework.messaging.PollableChannel)56 ErrorMessage (org.springframework.messaging.support.ErrorMessage)52 Matchers.containsString (org.hamcrest.Matchers.containsString)50 MessagingException (org.springframework.messaging.MessagingException)50 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)43 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)41 Assert.assertEquals (org.junit.Assert.assertEquals)40