Search in sources :

Example 6 with MessageHistory

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

the class JmsMessageDrivenChannelAdapterParserTests method adapterWithMessageSelector.

@Test
public void adapterWithMessageSelector() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsInboundWithMessageSelector.xml", this.getClass());
    PollableChannel output = (PollableChannel) context.getBean("output2");
    Message<?> message = output.receive(timeoutOnReceive);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "messageDrivenAdapter", 0);
    assertNotNull(componentHistoryRecord);
    JmsMessageDrivenEndpoint endpoint = context.getBean("messageDrivenAdapter", JmsMessageDrivenEndpoint.class);
    assertEquals("jms:message-driven-channel-adapter", componentHistoryRecord.get("type"));
    assertNotNull("message should not be null", message);
    assertEquals("test [with selector: TestProperty = 'foo']", message.getPayload());
    endpoint.stop();
    context.close();
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Properties(java.util.Properties) JmsMessageDrivenEndpoint(org.springframework.integration.jms.JmsMessageDrivenEndpoint) Test(org.junit.Test)

Example 7 with MessageHistory

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

the class AbstractMongoDbMessageGroupStoreTests method testWithMessageHistory.

@Test
@MongoDbAvailable
public void testWithMessageHistory() throws Exception {
    this.cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
    MessageGroupStore store = this.getMessageGroupStore();
    store.getMessageGroup(1);
    Message<?> message = new GenericMessage<String>("Hello");
    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.addMessagesToGroup(1, message);
    MessageGroup group = store.getMessageGroup(1);
    assertNotNull(group);
    Collection<Message<?>> messages = group.getMessages();
    assertTrue(!messages.isEmpty());
    message = messages.iterator().next();
    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 : MongoClient(com.mongodb.MongoClient) GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) AbstractBatchingMessageGroupStore(org.springframework.integration.store.AbstractBatchingMessageGroupStore) MessageGroupStore(org.springframework.integration.store.MessageGroupStore) SimpleMongoDbFactory(org.springframework.data.mongodb.core.SimpleMongoDbFactory) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) MessageGroup(org.springframework.integration.store.MessageGroup) Properties(java.util.Properties) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 8 with MessageHistory

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

the class RedisMessageStoreTests method testWithMessageHistory.

@Test
@RedisAvailable
public void testWithMessageHistory() throws Exception {
    RedisConnectionFactory jcf = this.getConnectionFactoryForTest();
    RedisMessageStore store = new RedisMessageStore(jcf);
    Message<?> message = new GenericMessage<String>("Hello");
    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());
    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 : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) DirectChannel(org.springframework.integration.channel.DirectChannel) Properties(java.util.Properties) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 9 with MessageHistory

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

the class EventInboundChannelAdapterParserTests method validateUsageWithHistory.

@Test
public void validateUsageWithHistory() {
    PollableChannel channel = context.getBean("input", PollableChannel.class);
    assertEquals(ContextRefreshedEvent.class, channel.receive(0).getPayload().getClass());
    context.publishEvent(new SampleEvent("hello"));
    Message<?> message = channel.receive(0);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "eventAdapterSimple", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("event:inbound-channel-adapter", componentHistoryRecord.get("type"));
    assertNotNull(message);
    assertEquals(SampleEvent.class, message.getPayload().getClass());
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) PollableChannel(org.springframework.messaging.PollableChannel) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with MessageHistory

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

the class ConnectionToConnectionTests method testConnectGuts.

@SuppressWarnings("unchecked")
private void testConnectGuts(AbstractClientConnectionFactory client, AbstractServerConnectionFactory server, String gatewayName, boolean expectExceptionOnClose) throws Exception {
    TestingUtilities.waitListening(server, null);
    client.setPort(server.getPort());
    client.start();
    for (int i = 0; i < 100; i++) {
        TcpConnection connection = client.getConnection();
        connection.send(MessageBuilder.withPayload("Test").build());
        Message<?> message = serverSideChannel.receive(10000);
        assertNotNull(message);
        MessageHistory history = MessageHistory.read(message);
        // org.springframework.integration.test.util.TestUtils
        Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, gatewayName, 0);
        assertNotNull(componentHistoryRecord);
        assertTrue(componentHistoryRecord.get("type").equals("ip:tcp-inbound-gateway"));
        assertNotNull(message);
        assertEquals("Test", new String((byte[]) message.getPayload()));
    }
    int clientOpens = 0;
    int clientCloses = 0;
    int serverOpens = 0;
    int serverCloses = 0;
    int clientExceptions = 0;
    Message<TcpConnectionEvent> eventMessage;
    int i = 0;
    while (i++ < (expectExceptionOnClose ? 600 : 400) && (eventMessage = (Message<TcpConnectionEvent>) events.receive(10000)) != null) {
        TcpConnectionEvent event = eventMessage.getPayload();
        if (event.getConnectionFactoryName().startsWith("client")) {
            if (event instanceof TcpConnectionOpenEvent) {
                clientOpens++;
            } else if (event instanceof TcpConnectionCloseEvent) {
                clientCloses++;
            } else if (event instanceof TcpConnectionExceptionEvent) {
                clientExceptions++;
            }
        } else if (event.getConnectionFactoryName().startsWith("server")) {
            if (event instanceof TcpConnectionOpenEvent) {
                serverOpens++;
            } else if (event instanceof TcpConnectionCloseEvent) {
                serverCloses++;
            }
        }
    }
    assertEquals(100, clientOpens);
    assertEquals(100, clientCloses);
    if (expectExceptionOnClose) {
        assertEquals(100, clientExceptions);
    }
    assertEquals(100, serverOpens);
    assertEquals(100, serverCloses);
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) TcpConnectionCloseEvent(org.springframework.integration.ip.tcp.connection.TcpConnectionCloseEvent) TcpConnectionOpenEvent(org.springframework.integration.ip.tcp.connection.TcpConnectionOpenEvent) Message(org.springframework.messaging.Message) TcpConnection(org.springframework.integration.ip.tcp.connection.TcpConnection) Properties(java.util.Properties) TcpConnectionEvent(org.springframework.integration.ip.tcp.connection.TcpConnectionEvent) TcpConnectionExceptionEvent(org.springframework.integration.ip.tcp.connection.TcpConnectionExceptionEvent)

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