use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-cloud-stream by spring-cloud.
the class TestChannelBinderProvisioner method provisionDestination.
private SubscribableChannel provisionDestination(String name, boolean pubSub) {
String destinationName = name + ".destination";
SubscribableChannel destination = this.provisionedDestinations.get(destinationName);
if (destination == null) {
destination = pubSub ? new PublishSubscribeChannel() : new DirectChannel();
((AbstractMessageChannel) destination).setBeanName(destinationName);
((AbstractMessageChannel) destination).setComponentName(destinationName);
this.provisionedDestinations.put(destinationName, destination);
}
return destination;
}
use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-cloud-stream by spring-cloud.
the class AbstractMessageChannelBinder method registerErrorInfrastructure.
/**
* Register an error channel for the destination when an async send error is received.
* Bridge the channel to the global error channel (if present).
* @param destination the destination.
* @return the channel.
*/
private SubscribableChannel registerErrorInfrastructure(ProducerDestination destination) {
ConfigurableListableBeanFactory beanFactory = getApplicationContext().getBeanFactory();
String errorChannelName = errorsBaseName(destination);
SubscribableChannel errorChannel = null;
if (getApplicationContext().containsBean(errorChannelName)) {
Object errorChannelObject = getApplicationContext().getBean(errorChannelName);
if (!(errorChannelObject instanceof SubscribableChannel)) {
throw new IllegalStateException("Error channel '" + errorChannelName + "' must be a SubscribableChannel");
}
errorChannel = (SubscribableChannel) errorChannelObject;
} else {
errorChannel = new PublishSubscribeChannel();
beanFactory.registerSingleton(errorChannelName, errorChannel);
errorChannel = (PublishSubscribeChannel) beanFactory.initializeBean(errorChannel, errorChannelName);
}
MessageChannel defaultErrorChannel = null;
if (getApplicationContext().containsBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME)) {
defaultErrorChannel = getApplicationContext().getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, MessageChannel.class);
}
if (defaultErrorChannel != null) {
BridgeHandler errorBridge = new BridgeHandler();
errorBridge.setOutputChannel(defaultErrorChannel);
errorChannel.subscribe(errorBridge);
String errorBridgeHandlerName = getErrorBridgeName(destination);
beanFactory.registerSingleton(errorBridgeHandlerName, errorBridge);
beanFactory.initializeBean(errorBridge, errorBridgeHandlerName);
}
return errorChannel;
}
use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.
the class MessagingGatewayTests method validateErrorChannelWithSuccessfulReply.
// should not fail but it does now
@Test
public void validateErrorChannelWithSuccessfulReply() {
TestUtils.TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
testApplicationContext.refresh();
DirectChannel reqChannel = new DirectChannel();
reqChannel.subscribe(message -> {
throw new RuntimeException("ooops");
});
PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyOneWayErrorService());
handler.setBeanFactory(testApplicationContext);
handler.afterPropertiesSet();
errorChannel.subscribe(handler);
this.messagingGateway = new MessagingGatewaySupport() {
};
this.messagingGateway.setRequestChannel(reqChannel);
this.messagingGateway.setErrorChannel(errorChannel);
this.messagingGateway.setReplyChannel(null);
this.messagingGateway.setBeanFactory(mock(BeanFactory.class));
this.messagingGateway.afterPropertiesSet();
this.messagingGateway.start();
this.messagingGateway.send("hello");
testApplicationContext.close();
}
use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.
the class DefaultConfiguringBeanFactoryPostProcessor method registerErrorChannel.
/**
* Register an error channel in the given BeanDefinitionRegistry.
*/
private void registerErrorChannel(BeanDefinitionRegistry registry) {
if (this.logger.isInfoEnabled()) {
this.logger.info("No bean named '" + IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME + "' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.");
}
registry.registerBeanDefinition(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, new RootBeanDefinition(PublishSubscribeChannel.class));
BeanDefinition loggingHandler = BeanDefinitionBuilder.genericBeanDefinition(LoggingHandler.class).addConstructorArgValue("ERROR").getBeanDefinition();
String errorLoggerBeanName = ERROR_LOGGER_BEAN_NAME + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX;
registry.registerBeanDefinition(errorLoggerBeanName, loggingHandler);
BeanDefinitionBuilder loggingEndpointBuilder = BeanDefinitionBuilder.genericBeanDefinition(ConsumerEndpointFactoryBean.class).addPropertyReference("handler", errorLoggerBeanName).addPropertyValue("inputChannelName", IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
BeanComponentDefinition componentDefinition = new BeanComponentDefinition(loggingEndpointBuilder.getBeanDefinition(), ERROR_LOGGER_BEAN_NAME);
BeanDefinitionReaderUtils.registerBeanDefinition(componentDefinition, registry);
}
use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.
the class PublishSubscribeChannelParserTests method applySequenceEnabledWithTaskExecutor.
@Test
public void applySequenceEnabledWithTaskExecutor() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithApplySequenceEnabledAndTaskExecutor");
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
assertTrue((Boolean) dispatcherAccessor.getPropertyValue("applySequence"));
Executor executor = (Executor) dispatcherAccessor.getPropertyValue("executor");
assertNotNull(executor);
assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executor);
Executor innerExecutor = (Executor) executorAccessor.getPropertyValue("executor");
assertEquals(context.getBean("pool"), innerExecutor);
context.close();
}
Aggregations