use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class MessagingAnnotationPostProcessorTests method testMessageEndpointAnnotationInheritedWithProxy.
@Test
public void testMessageEndpointAnnotationInheritedWithProxy() {
TestApplicationContext context = TestUtils.createTestApplicationContext();
DirectChannel inputChannel = new DirectChannel();
QueueChannel outputChannel = new QueueChannel();
context.registerChannel("inputChannel", inputChannel);
context.registerChannel("outputChannel", outputChannel);
MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
postProcessor.setBeanFactory(context.getBeanFactory());
postProcessor.afterPropertiesSet();
ProxyFactory proxyFactory = new ProxyFactory(new SimpleAnnotatedEndpointSubclass());
Object proxy = proxyFactory.getProxy();
postProcessor.postProcessAfterInitialization(proxy, "proxy");
context.refresh();
inputChannel.send(new GenericMessage<String>("world"));
Message<?> message = outputChannel.receive(1000);
assertEquals("hello world", message.getPayload());
context.stop();
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class InnerDefinitionHandlerAwareEndpointParserTests method testRouterDefinitionSuccess.
private void testRouterDefinitionSuccess(String configProperty) {
ApplicationContext ac = this.bootStrap(configProperty);
EventDrivenConsumer splitter = (EventDrivenConsumer) ac.getBean("testRouter");
Assert.assertNotNull(splitter);
MessageBuilder<String> inChannelMessageBuilder = MessageBuilder.withPayload("1");
Message<String> inMessage = inChannelMessageBuilder.build();
DirectChannel inChannel = (DirectChannel) ac.getBean("inChannel");
inChannel.send(inMessage);
PollableChannel channel1 = (PollableChannel) ac.getBean("channel1");
Assert.assertTrue(channel1.receive().getPayload().equals("1"));
inChannelMessageBuilder = MessageBuilder.withPayload("2");
inMessage = inChannelMessageBuilder.build();
inChannel.send(inMessage);
PollableChannel channel2 = (PollableChannel) ac.getBean("channel2");
Assert.assertTrue(channel2.receive().getPayload().equals("2"));
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class ControlBusTests method testControlHeaderChannelReaper.
@Test
public void testControlHeaderChannelReaper() throws InterruptedException {
MessagingTemplate messagingTemplate = new MessagingTemplate();
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
Message<?> result = this.output.receive(0);
assertNotNull(result);
// No channels in the registry
assertEquals(0, result.getPayload());
this.registry.channelToChannelName(new DirectChannel());
// Sleep a bit to be sure that we aren't reaped by registry TTL as 60000
Thread.sleep(100);
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
result = this.output.receive(0);
assertNotNull(result);
assertEquals(1, result.getPayload());
// Some DirectFieldAccessor magic to modify 'expireAt' to the past to avoid timing issues on high-loaded build
Object messageChannelWrapper = TestUtils.getPropertyValue(this.registry, "channels", Map.class).values().iterator().next();
DirectFieldAccessor dfa = new DirectFieldAccessor(messageChannelWrapper);
dfa.setPropertyValue("expireAt", System.currentTimeMillis() - 60000);
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.runReaper()");
messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
result = this.output.receive(0);
assertNotNull(result);
assertEquals(0, result.getPayload());
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class IntegrationFlowDefinition method wireTap.
/**
* Populate the {@code Wire Tap} EI Pattern specific
* {@link org.springframework.messaging.support.ChannelInterceptor} implementation
* to the current {@link #currentMessageChannel}.
* <p> It is useful when an implicit {@link MessageChannel} is used between endpoints:
* <pre class="code">
* {@code
* .transform("payload")
* .wireTap(new WireTap(tapChannel().selector(m -> m.getPayload().equals("foo")))
* .channel("foo")
* }
* </pre>
* This method can be used after any {@link #channel} for explicit {@link MessageChannel},
* but with the caution do not impact existing {@link org.springframework.messaging.support.ChannelInterceptor}s.
* @param wireTapSpec the {@link WireTapSpec} to use.
* <p> When this EIP-method is used in the end of flow, it appends {@code nullChannel} to terminate flow properly,
* Otherwise {@code Dispatcher has no subscribers} exception is thrown for implicit {@link DirectChannel}.
* @return the current {@link IntegrationFlowDefinition}.
*/
public B wireTap(WireTapSpec wireTapSpec) {
WireTap interceptor = wireTapSpec.get();
if (this.currentMessageChannel == null || !(this.currentMessageChannel instanceof ChannelInterceptorAware)) {
this.implicitChannel = true;
channel(new DirectChannel());
}
addComponent(wireTapSpec);
((ChannelInterceptorAware) this.currentMessageChannel).addInterceptor(interceptor);
return _this();
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class IntegrationFlowDefinition method register.
@SuppressWarnings("unchecked")
private <S extends ConsumerEndpointSpec<S, ? extends MessageHandler>> B register(S endpointSpec, Consumer<S> endpointConfigurer) {
if (endpointConfigurer != null) {
endpointConfigurer.accept(endpointSpec);
}
MessageChannel inputChannel = this.currentMessageChannel;
this.currentMessageChannel = null;
if (inputChannel == null) {
inputChannel = new DirectChannel();
this.registerOutputChannelIfCan(inputChannel);
}
Tuple2<ConsumerEndpointFactoryBean, ? extends MessageHandler> factoryBeanTuple2 = endpointSpec.get();
addComponents(endpointSpec.getComponentsToRegister());
if (inputChannel instanceof MessageChannelReference) {
factoryBeanTuple2.getT1().setInputChannelName(((MessageChannelReference) inputChannel).getName());
} else {
if (inputChannel instanceof FixedSubscriberChannelPrototype) {
String beanName = ((FixedSubscriberChannelPrototype) inputChannel).getName();
inputChannel = new FixedSubscriberChannel(factoryBeanTuple2.getT2());
if (beanName != null) {
((FixedSubscriberChannel) inputChannel).setBeanName(beanName);
}
registerOutputChannelIfCan(inputChannel);
}
factoryBeanTuple2.getT1().setInputChannel(inputChannel);
}
return addComponent(endpointSpec).currentComponent(factoryBeanTuple2.getT2());
}
Aggregations