Search in sources :

Example 36 with MessageHistory

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

the class JmsOutboundGatewayParserTests method gatewayMaintainsReplyChannelAndInboundHistory.

@Test
public void gatewayMaintainsReplyChannelAndInboundHistory() {
    ActiveMqTestUtils.prepare();
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("gatewayMaintainsReplyChannel.xml", this.getClass());
    SampleGateway gateway = context.getBean("gateway", SampleGateway.class);
    SubscribableChannel jmsInput = context.getBean("jmsInput", SubscribableChannel.class);
    MessageHandler handler = message -> {
        MessageHistory history = MessageHistory.read(message);
        assertNotNull(history);
        Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "inboundGateway", 0);
        assertNotNull(componentHistoryRecord);
        assertEquals("jms:inbound-gateway", componentHistoryRecord.get("type"));
        MessagingTemplate messagingTemplate = new MessagingTemplate();
        messagingTemplate.setDefaultDestination((MessageChannel) message.getHeaders().getReplyChannel());
        messagingTemplate.send(message);
    };
    jmsInput.subscribe(handler);
    String result = gateway.echo("hello");
    assertEquals("hello", result);
    JmsOutboundGateway gw1 = context.getBean("chain1$child.gateway.handler", JmsOutboundGateway.class);
    MessageChannel out = TestUtils.getPropertyValue(gw1, "outputChannel", MessageChannel.class);
    assertThat(out.getClass().getSimpleName(), equalTo("ReplyForwardingMessageChannel"));
    JmsOutboundGateway gw2 = context.getBean("chain2$child.gateway.handler", JmsOutboundGateway.class);
    out = TestUtils.getPropertyValue(gw2, "outputChannel", MessageChannel.class);
    assertThat(out.getClass().getName(), containsString("MessageHandlerChain$"));
    context.close();
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) AbstractRequestHandlerAdvice(org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice) SubscribableChannel(org.springframework.messaging.SubscribableChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) TestUtils(org.springframework.integration.test.util.TestUtils) MessagingTemplate(org.springframework.integration.core.MessagingTemplate) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) MessageBuilder(org.springframework.integration.support.MessageBuilder) Session(javax.jms.Session) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageHistory(org.springframework.integration.history.MessageHistory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Assert.fail(org.junit.Assert.fail) Message(org.springframework.messaging.Message) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) Method(java.lang.reflect.Method) DeliveryMode(javax.jms.DeliveryMode) Properties(java.util.Properties) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) MessageChannel(org.springframework.messaging.MessageChannel) ExpressionEvaluatingMessageProcessor(org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor) Queue(javax.jms.Queue) BeanDefinitionParsingException(org.springframework.beans.factory.parsing.BeanDefinitionParsingException) Destination(javax.jms.Destination) MessageHandler(org.springframework.messaging.MessageHandler) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Expression(org.springframework.expression.Expression) MessageConverter(org.springframework.jms.support.converter.MessageConverter) GenericMessage(org.springframework.messaging.support.GenericMessage) Matchers.containsString(org.hamcrest.Matchers.containsString) NotReadablePropertyException(org.springframework.beans.NotReadablePropertyException) Assert.assertEquals(org.junit.Assert.assertEquals) StubMessageConverter(org.springframework.integration.jms.StubMessageConverter) Mockito.mock(org.mockito.Mockito.mock) MessageHistory(org.springframework.integration.history.MessageHistory) MessagingTemplate(org.springframework.integration.core.MessagingTemplate) MessageHandler(org.springframework.messaging.MessageHandler) MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Test(org.junit.Test)

Example 37 with MessageHistory

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

the class AbstractMongoDbMessageStoreTests method testWithMessageHistory.

@Test
@MongoDbAvailable
public void testWithMessageHistory() throws Exception {
    cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageStore store = getMessageStore();
    Foo foo = new Foo();
    foo.setName("foo");
    Message<?> message = MessageBuilder.withPayload(foo).setHeader("foo", foo).setHeader("bar", new Bar("bar")).setHeader("baz", new Baz()).setHeader("abc", new Abc()).setHeader("xyz", new Xyz()).build();
    DirectChannel fooChannel = new DirectChannel();
    fooChannel.setBeanName("fooChannel");
    DirectChannel barChannel = new DirectChannel();
    barChannel.setBeanName("barChannel");
    message = MessageHistory.write(message, fooChannel);
    message = MessageHistory.write(message, barChannel);
    store.addMessage(message);
    message = store.getMessage(message.getHeaders().getId());
    assertNotNull(message);
    assertTrue(message.getHeaders().get("foo") instanceof Foo);
    assertTrue(message.getHeaders().get("bar") instanceof Bar);
    assertTrue(message.getHeaders().get("baz") instanceof Baz);
    assertTrue(message.getHeaders().get("abc") instanceof Abc);
    assertTrue(message.getHeaders().get("xyz") instanceof Xyz);
    MessageHistory messageHistory = MessageHistory.read(message);
    assertNotNull(messageHistory);
    assertEquals(2, messageHistory.size());
    Properties fooChannelHistory = messageHistory.get(0);
    assertEquals("fooChannel", fooChannelHistory.get("name"));
    assertEquals("channel", fooChannelHistory.get("type"));
}
Also used : MessageStore(org.springframework.integration.store.MessageStore) MongoClient(com.mongodb.MongoClient) MessageHistory(org.springframework.integration.history.MessageHistory) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) DirectChannel(org.springframework.integration.channel.DirectChannel) Properties(java.util.Properties) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Aggregations

MessageHistory (org.springframework.integration.history.MessageHistory)37 Test (org.junit.Test)34 Properties (java.util.Properties)26 GenericMessage (org.springframework.messaging.support.GenericMessage)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 DirectChannel (org.springframework.integration.channel.DirectChannel)8 PollableChannel (org.springframework.messaging.PollableChannel)8 Message (org.springframework.messaging.Message)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 QueueChannel (org.springframework.integration.channel.QueueChannel)3 EnableMessageHistory (org.springframework.integration.config.EnableMessageHistory)3 MongoClient (com.mongodb.MongoClient)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)2 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)2 TcpConnection (org.springframework.integration.ip.tcp.connection.TcpConnection)2 JmsMessageDrivenEndpoint (org.springframework.integration.jms.JmsMessageDrivenEndpoint)2 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)2 MessageChannel (org.springframework.messaging.MessageChannel)2