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();
}
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());
}
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());
}
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();
}
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();
}
Aggregations