Search in sources :

Example 6 with IntegrationMessageHeaderAccessor

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

the class BroadcastingDispatcherTests method applySequenceEnabled.

@Test
public void applySequenceEnabled() {
    BroadcastingDispatcher dispatcher = new BroadcastingDispatcher();
    dispatcher.setApplySequence(true);
    final List<Message<?>> messages = Collections.synchronizedList(new ArrayList<Message<?>>());
    MessageHandler target1 = new MessageStoringTestEndpoint(messages);
    MessageHandler target2 = new MessageStoringTestEndpoint(messages);
    MessageHandler target3 = new MessageStoringTestEndpoint(messages);
    dispatcher.addHandler(target1);
    dispatcher.addHandler(target2);
    dispatcher.addHandler(target3);
    Message<?> inputMessage = new GenericMessage<String>("test");
    Object originalId = inputMessage.getHeaders().getId();
    dispatcher.dispatch(inputMessage);
    assertEquals(3, messages.size());
    assertEquals(1, new IntegrationMessageHeaderAccessor(messages.get(0)).getSequenceNumber());
    assertEquals(3, new IntegrationMessageHeaderAccessor(messages.get(0)).getSequenceSize());
    assertEquals(originalId, new IntegrationMessageHeaderAccessor(messages.get(0)).getCorrelationId());
    assertEquals(2, new IntegrationMessageHeaderAccessor(messages.get(1)).getSequenceNumber());
    assertEquals(3, new IntegrationMessageHeaderAccessor(messages.get(1)).getSequenceSize());
    assertEquals(originalId, new IntegrationMessageHeaderAccessor(messages.get(1)).getCorrelationId());
    assertEquals(3, new IntegrationMessageHeaderAccessor(messages.get(2)).getSequenceNumber());
    assertEquals(3, new IntegrationMessageHeaderAccessor(messages.get(2)).getSequenceSize());
    assertEquals(originalId, new IntegrationMessageHeaderAccessor(messages.get(2)).getCorrelationId());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHandler(org.springframework.messaging.MessageHandler) Test(org.junit.Test)

Example 7 with IntegrationMessageHeaderAccessor

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

the class CorrelationIdTests method testCorrelationIdWithSplitterWhenNotValueSetOnIncomingMessage.

@Test
public void testCorrelationIdWithSplitterWhenNotValueSetOnIncomingMessage() throws Exception {
    Message<?> message = new GenericMessage<String>("test1,test2");
    QueueChannel testChannel = new QueueChannel();
    MethodInvokingSplitter splitter = new MethodInvokingSplitter(new TestBean(), TestBean.class.getMethod("split", String.class));
    splitter.setOutputChannel(testChannel);
    splitter.handleMessage(message);
    Message<?> reply1 = testChannel.receive(100);
    Message<?> reply2 = testChannel.receive(100);
    assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply1).getCorrelationId());
    assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply2).getCorrelationId());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MethodInvokingSplitter(org.springframework.integration.splitter.MethodInvokingSplitter) QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 8 with IntegrationMessageHeaderAccessor

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

the class CorrelationIdTests method testCorrelationIdPassedIfAvailable.

@Test
public void testCorrelationIdPassedIfAvailable() {
    Object correlationId = "123-ABC";
    Message<String> message = MessageBuilder.withPayload("test").setCorrelationId(correlationId).build();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel(1);
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "upperCase");
    serviceActivator.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
    endpoint.start();
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertEquals(correlationId, new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 9 with IntegrationMessageHeaderAccessor

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

the class HeaderEnricherTests method correlationIdValue.

@Test
public void correlationIdValue() {
    MessagingTemplate template = new MessagingTemplate();
    MessageChannel channel = context.getBean("correlationIdValueInput", MessageChannel.class);
    Message<?> result = template.sendAndReceive(channel, new GenericMessage<String>("test"));
    assertNotNull(result);
    assertEquals("ABC", new IntegrationMessageHeaderAccessor(result).getCorrelationId());
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageChannel(org.springframework.messaging.MessageChannel) Test(org.junit.Test)

Example 10 with IntegrationMessageHeaderAccessor

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

the class HeaderEnricherTests method expirationDateRef.

@Test
public void expirationDateRef() {
    MessagingTemplate template = new MessagingTemplate();
    MessageChannel channel = context.getBean("expirationDateRefInput", MessageChannel.class);
    Message<?> result = template.sendAndReceive(channel, new GenericMessage<String>("test"));
    assertNotNull(result);
    assertEquals(new Long(9999), new IntegrationMessageHeaderAccessor(result).getExpirationDate());
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageChannel(org.springframework.messaging.MessageChannel) Test(org.junit.Test)

Aggregations

IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)68 Test (org.junit.Test)56 QueueChannel (org.springframework.integration.channel.QueueChannel)32 Message (org.springframework.messaging.Message)21 GenericMessage (org.springframework.messaging.support.GenericMessage)19 MessageChannel (org.springframework.messaging.MessageChannel)15 ArrayList (java.util.ArrayList)10 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)9 DirectChannel (org.springframework.integration.channel.DirectChannel)8 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)6 List (java.util.List)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 MessageSequenceComparator (org.springframework.integration.aggregator.MessageSequenceComparator)4 Aggregator (org.springframework.integration.annotation.Aggregator)4 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)3 MessageGroup (org.springframework.integration.store.MessageGroup)3 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)3