Search in sources :

Example 91 with Message

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

the class AggregatorParserTests method testAggregation.

@Test
public void testAggregation() {
    MessageChannel input = (MessageChannel) context.getBean("aggregatorWithReferenceInput");
    TestAggregatorBean aggregatorBean = (TestAggregatorBean) context.getBean("aggregatorBean");
    List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
    outboundMessages.add(createMessage("123", "id1", 3, 1, null));
    outboundMessages.add(createMessage("789", "id1", 3, 3, null));
    outboundMessages.add(createMessage("456", "id1", 3, 2, null));
    outboundMessages.forEach(input::send);
    assertEquals("One and only one message must have been aggregated", 1, aggregatorBean.getAggregatedMessages().size());
    Message<?> aggregatedMessage = aggregatorBean.getAggregatedMessages().get("id1");
    assertEquals("The aggregated message payload is not correct", "123456789", aggregatedMessage.getPayload());
    Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
    Object handler = context.getBean("aggregatorWithReference.handler");
    assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory"));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 92 with Message

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

the class AggregatorParserTests method testAggregationByExpression.

@Test
public void testAggregationByExpression() {
    MessageChannel input = (MessageChannel) context.getBean("aggregatorWithExpressionsInput");
    SubscribableChannel outputChannel = (SubscribableChannel) context.getBean("aggregatorWithExpressionsOutput");
    final AtomicReference<Message<?>> aggregatedMessage = new AtomicReference<Message<?>>();
    outputChannel.subscribe(aggregatedMessage::set);
    List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
    outboundMessages.add(MessageBuilder.withPayload("123").setHeader("foo", "1").build());
    outboundMessages.add(MessageBuilder.withPayload("456").setHeader("foo", "1").build());
    outboundMessages.add(MessageBuilder.withPayload("789").setHeader("foo", "1").build());
    outboundMessages.forEach(input::send);
    assertEquals("The aggregated message payload is not correct", "[123]", aggregatedMessage.get().getPayload().toString());
    Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
    Object handler = context.getBean("aggregatorWithExpressions.handler");
    assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory"));
    assertTrue(TestUtils.getPropertyValue(handler, "expireGroupsUponTimeout", Boolean.class));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Test(org.junit.Test)

Example 93 with Message

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

the class AggregatorParserTests method testAggregationWithMessageGroupProcessorAndStrategies.

@Test
public void testAggregationWithMessageGroupProcessorAndStrategies() {
    QueueChannel output = this.context.getBean("outputChannel", QueueChannel.class);
    output.purge(null);
    MessageChannel input = (MessageChannel) context.getBean("aggregatorWithCustomMGPReferenceInput");
    List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
    outboundMessages.add(createMessage("123", "id1", 3, 1, null));
    outboundMessages.add(createMessage("789", "id1", 3, 3, null));
    outboundMessages.add(createMessage("456", "id1", 3, 2, null));
    outboundMessages.forEach(input::send);
    assertEquals(3, output.getQueueSize());
    output.purge(null);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 94 with Message

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

the class AggregatorParserTests method testSimpleJavaBeanAggregator.

@Test
public void testSimpleJavaBeanAggregator() {
    List<Message<?>> outboundMessages = new ArrayList<Message<?>>();
    MessageChannel input = (MessageChannel) context.getBean("aggregatorWithReferenceAndMethodInput");
    outboundMessages.add(createMessage(1L, "id1", 3, 1, null));
    outboundMessages.add(createMessage(2L, "id1", 3, 3, null));
    outboundMessages.add(createMessage(3L, "id1", 3, 2, null));
    outboundMessages.forEach(input::send);
    PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
    Message<?> response = outputChannel.receive(10);
    Assert.assertEquals(6L, response.getPayload());
    Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
    Object handler = context.getBean("aggregatorWithReferenceAndMethod.handler");
    assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory"));
}
Also used : Message(org.springframework.messaging.Message) MessageChannel(org.springframework.messaging.MessageChannel) ArrayList(java.util.ArrayList) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 95 with Message

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

the class CorrelatingMessageHandlerIntegrationTests method completesAfterThreshold.

@Test
public void completesAfterThreshold() throws Exception {
    defaultHandler.setReleaseStrategy(new MessageCountReleaseStrategy());
    MessageChannel discardChannel = mock(MessageChannel.class);
    when(discardChannel.send(any(Message.class))).thenReturn(true);
    defaultHandler.setDiscardChannel(discardChannel);
    Message<?> message1 = correlatedMessage(1, 2, 1);
    Message<?> message2 = correlatedMessage(1, 2, 2);
    defaultHandler.handleMessage(message1);
    verify(outputChannel).send(message1);
    defaultHandler.handleMessage(message2);
    verify(outputChannel, never()).send(message2);
    verify(discardChannel).send(message2);
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) 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