Search in sources :

Example 31 with MessageHistory

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

the class UdpUnicastEndToEndTests method run.

/**
 * Instantiate the receiving context
 */
@SuppressWarnings("unchecked")
@Override
public void run() {
    @SuppressWarnings("resource") AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("testIp-in-context.xml", UdpUnicastEndToEndTests.class);
    UnicastReceivingChannelAdapter inbound = ctx.getBean(UnicastReceivingChannelAdapter.class);
    int n = 0;
    try {
        while (!inbound.isListening()) {
            Thread.sleep(100);
            if (n++ > 100) {
                throw new RuntimeException("Failed to start listening");
            }
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new RuntimeException("interrupted");
    }
    this.receiverPort = inbound.getPort();
    while (okToRun) {
        try {
            readyToReceive.countDown();
            sentFirst.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        QueueChannel channel = ctx.getBean("udpOutChannel", QueueChannel.class);
        finalMessage = (Message<byte[]>) channel.receive();
        MessageHistory history = MessageHistory.read(finalMessage);
        Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "udpReceiver", 0);
        assertNotNull(componentHistoryRecord);
        assertEquals("ip:udp-inbound-channel-adapter", componentHistoryRecord.get("type"));
        firstReceived.countDown();
        try {
            doneProcessing.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    ctx.stop();
    ctx.close();
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) QueueChannel(org.springframework.integration.channel.QueueChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Properties(java.util.Properties)

Example 32 with MessageHistory

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

the class TwitterAnnouncer method search.

public void search(Message<?> search) {
    MessageHistory history = MessageHistory.read(search);
    Tweet tweet = (Tweet) search.getPayload();
    logger.info("A search item was received " + tweet.getCreatedAt() + " with text " + tweet.getText());
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) Tweet(org.springframework.social.twitter.api.Tweet)

Example 33 with MessageHistory

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

the class SharedConnectionTests method test1.

/**
 * Tests a loopback. The client-side outbound adapter sends a message over
 * a connection from the client connection factory; the server side
 * receives the message, puts in on a channel which is the input channel
 * for the outbound adapter that's sharing the connections. The response
 * comes back to an inbound adapter that is sharing the client's
 * connection and we verify we get the echo back as expected.
 *
 * @throws Exception
 */
@Test
public void test1() throws Exception {
    TestingUtilities.waitListening(this.server, null);
    this.client.setPort(this.server.getPort());
    this.ctx.getBeansOfType(ConsumerEndpointFactoryBean.class).values().forEach(c -> c.start());
    MessageChannel input = ctx.getBean("input", MessageChannel.class);
    input.send(MessageBuilder.withPayload("Test").build());
    QueueChannel replies = ctx.getBean("replies", QueueChannel.class);
    Message<?> message = replies.receive(10000);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "inboundClient", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("ip:tcp-inbound-channel-adapter", componentHistoryRecord.getProperty("type"));
    assertNotNull(message);
    assertEquals("Test", message.getPayload());
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) MessageChannel(org.springframework.messaging.MessageChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) Properties(java.util.Properties) Test(org.junit.Test)

Example 34 with MessageHistory

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

the class JmsChannelHistoryTests method testMessageHistory.

@Test
public void testMessageHistory() throws Exception {
    AbstractMessageListenerContainer mlContainer = mock(AbstractMessageListenerContainer.class);
    JmsTemplate template = mock(JmsTemplate.class);
    SubscribableJmsChannel channel = new SubscribableJmsChannel(mlContainer, template);
    channel.setShouldTrack(true);
    channel.setBeanName("jmsChannel");
    Message<String> message = new GenericMessage<String>("hello");
    doAnswer(invocation -> {
        @SuppressWarnings("unchecked") Message<String> msg = invocation.getArgument(0);
        MessageHistory history = MessageHistory.read(msg);
        assertTrue(history.get(0).contains("jmsChannel"));
        return null;
    }).when(template).convertAndSend(Mockito.any(Message.class));
    channel.send(message);
    verify(template, times(1)).convertAndSend(Mockito.any(Message.class));
    channel.stop();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) SubscribableJmsChannel(org.springframework.integration.jms.SubscribableJmsChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) JmsTemplate(org.springframework.jms.core.JmsTemplate) AbstractMessageListenerContainer(org.springframework.jms.listener.AbstractMessageListenerContainer) Test(org.junit.Test)

Example 35 with MessageHistory

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

the class JmsInboundChannelAdapterParserTests method adapterWithJmsTemplate.

@Test
public void adapterWithJmsTemplate() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsInboundWithJmsTemplate.xml", this.getClass());
    PollableChannel output = (PollableChannel) context.getBean("output");
    Message<?> message = output.receive(timeoutOnReceive);
    MessageHistory history = MessageHistory.read(message);
    assertNotNull(history);
    Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "inboundAdapter", 0);
    assertNotNull(componentHistoryRecord);
    assertEquals("jms:inbound-channel-adapter", componentHistoryRecord.get("type"));
    assertNotNull("message should not be null", message);
    assertEquals("polling-test", message.getPayload());
    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) Test(org.junit.Test)

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