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