Class PublishSubscribeChannel
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.channel.AbstractMessageChannel
org.springframework.integration.channel.AbstractSubscribableChannel
org.springframework.integration.channel.AbstractExecutorChannel
org.springframework.integration.channel.PublishSubscribeChannel
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,BroadcastCapableChannel
,ExecutorChannelInterceptorAware
,ExpressionCapable
,IntegrationPattern
,NamedComponent
,IntegrationManagement
,SubscribableChannelManagement
,TrackableComponent
,MessageChannel
,SubscribableChannel
,InterceptableChannel
public class PublishSubscribeChannel extends AbstractExecutorChannel implements BroadcastCapableChannel
A channel that sends Messages to each of its subscribers.
- Author:
- Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.channel.AbstractExecutorChannel
AbstractExecutorChannel.MessageHandlingTask
Nested classes/interfaces inherited from class org.springframework.integration.channel.AbstractMessageChannel
AbstractMessageChannel.ChannelInterceptorList
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.channel.AbstractExecutorChannel
dispatcher, executor, executorInterceptorsSize, maxSubscribers
Fields inherited from class org.springframework.integration.channel.AbstractMessageChannel
interceptors, meters
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
-
Constructor Summary
Constructors Constructor Description PublishSubscribeChannel()
Create a PublishSubscribeChannel that will invoke the handlers in the message sender's thread.PublishSubscribeChannel(boolean requireSubscribers)
Create a PublishSubscribeChannel that will invoke the handlers in the message sender's thread considering the providedrequireSubscribers
flag.PublishSubscribeChannel(Executor executor)
Create a PublishSubscribeChannel that will use anExecutor
to invoke the handlers.PublishSubscribeChannel(Executor executor, boolean requireSubscribers)
Create a PublishSubscribeChannel that will use anExecutor
to invoke the handlers. -
Method Summary
Modifier and Type Method Description String
getComponentType()
Subclasses may implement this method to provide component type information.protected BroadcastingDispatcher
getDispatcher()
IntegrationPatternType
getIntegrationPatternType()
Return a pattern type this component implements.void
onInit()
Callback method for initialization.void
setApplySequence(boolean applySequence)
Specify whether to apply the sequence number and size headers to the messages prior to invoking the subscribed handlers.void
setErrorHandler(ErrorHandler errorHandler)
Provide anErrorHandler
strategy for handling Exceptions that occur downstream from this channel.void
setIgnoreFailures(boolean ignoreFailures)
Specify whether failures for one or more of the handlers should be ignored.void
setMinSubscribers(int minSubscribers)
If at least this number of subscribers receive the message,AbstractMessageChannel.send(org.springframework.messaging.Message)
will return true.Methods inherited from class org.springframework.integration.channel.AbstractExecutorChannel
addInterceptor, addInterceptor, hasExecutorInterceptors, removeInterceptor, removeInterceptor, setInterceptors, setMaxSubscribers
Methods inherited from class org.springframework.integration.channel.AbstractSubscribableChannel
doSend, getSubscriberCount, subscribe, unsubscribe
Methods inherited from class org.springframework.integration.channel.AbstractMessageChannel
destroy, getFullChannelName, getIChannelInterceptorList, getInterceptors, getMetricsCaptor, getOverrides, isLoggingEnabled, registerMetricsCaptor, send, send, setDatatypes, setLoggingEnabled, setMessageConverter, setShouldTrack
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.integration.channel.BroadcastCapableChannel
isBroadcast
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getManagedName, getManagedType, getThisAs, setManagedName, setManagedType
Methods inherited from interface org.springframework.messaging.support.InterceptableChannel
getInterceptors
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
Methods inherited from interface org.springframework.messaging.SubscribableChannel
subscribe, unsubscribe
-
Constructor Details
-
PublishSubscribeChannel
public PublishSubscribeChannel()Create a PublishSubscribeChannel that will invoke the handlers in the message sender's thread. -
PublishSubscribeChannel
public PublishSubscribeChannel(boolean requireSubscribers)Create a PublishSubscribeChannel that will invoke the handlers in the message sender's thread considering the providedrequireSubscribers
flag.- Parameters:
requireSubscribers
- if set to true, the sent message is considered as non-dispatched and rejected to the caller with the"Dispatcher has no subscribers"
.- Since:
- 5.4.3
-
PublishSubscribeChannel
Create a PublishSubscribeChannel that will use anExecutor
to invoke the handlers. If this is null, each invocation will occur in the message sender's thread.- Parameters:
executor
- The executor.
-
PublishSubscribeChannel
Create a PublishSubscribeChannel that will use anExecutor
to invoke the handlers. If this is null, each invocation will occur in the message sender's thread.- Parameters:
executor
- The executor.requireSubscribers
- if set to true, the sent message is considered as non-dispatched and rejected to the caller with the"Dispatcher has no subscribers"
.- Since:
- 5.4.3
-
-
Method Details
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classAbstractMessageChannel
-
getIntegrationPatternType
Description copied from interface:IntegrationPattern
Return a pattern type this component implements.- Specified by:
getIntegrationPatternType
in interfaceIntegrationPattern
- Overrides:
getIntegrationPatternType
in classAbstractExecutorChannel
- Returns:
- the
IntegrationPatternType
this component implements.
-
setErrorHandler
Provide anErrorHandler
strategy for handling Exceptions that occur downstream from this channel. This will only be applied if an Executor has been configured to dispatch the Messages for this channel. Otherwise, Exceptions will be thrown directly within the sending Thread. If no ErrorHandler is provided, and this channel does delegate its dispatching to an Executor, the default strategy is aMessagePublishingErrorHandler
that sends error messages to the failed request Message's error channel header if available or to the default 'errorChannel' otherwise.- Parameters:
errorHandler
- The error handler.- See Also:
PublishSubscribeChannel(Executor)
-
setIgnoreFailures
public void setIgnoreFailures(boolean ignoreFailures)Specify whether failures for one or more of the handlers should be ignored. By default this is false meaning that an Exception will be thrown whenever a handler fails. To override this and suppress Exceptions, set the value to true.- Parameters:
ignoreFailures
- true if failures should be ignored.
-
setApplySequence
public void setApplySequence(boolean applySequence)Specify whether to apply the sequence number and size headers to the messages prior to invoking the subscribed handlers. By default, this value is false meaning that sequence headers will not be applied. If planning to use an Aggregator downstream with the default correlation and completion strategies, you should set this flag to true.- Parameters:
applySequence
- true if the sequence information should be applied.
-
setMinSubscribers
public void setMinSubscribers(int minSubscribers)If at least this number of subscribers receive the message,AbstractMessageChannel.send(org.springframework.messaging.Message)
will return true. Default: 0.- Parameters:
minSubscribers
- The minimum number of subscribers.
-
onInit
public final void onInit()Callback method for initialization.- Overrides:
onInit
in classAbstractMessageChannel
-
getDispatcher
- Specified by:
getDispatcher
in classAbstractSubscribableChannel
-