Class PartitionedChannel
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.PartitionedChannel
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,ExecutorChannelInterceptorAware
,ComponentSourceAware
,ExpressionCapable
,IntegrationPattern
,NamedComponent
,IntegrationManagement
,SubscribableChannelManagement
,TrackableComponent
,MessageChannel
,SubscribableChannel
,InterceptableChannel
An
AbstractExecutorChannel
implementation for partitioned message dispatching.
Requires a number of partitions where each of them is backed by a dedicated thread.
The partitionKeyFunction
is used to determine to which partition the message
has to be dispatched.
By default, the IntegrationMessageHeaderAccessor.CORRELATION_ID
message header is used
for partition key.
The actual dispatching and threading logic is implemented in the PartitionedDispatcher
.
The default ThreadFactory
is based on the bean name of this channel plus -partition-thread-
.
Thus, every thread name will reflect a partition it belongs to.
The rest of the logic is similar to the ExecutorChannel
, which includes:
- load balancing for subscribers;
- fail-over and error handling;
- channel operations intercepting.
- Since:
- 6.1
- Author:
- Artem Bilan
- See Also:
-
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
Fields inherited from interface org.springframework.messaging.MessageChannel
INDEFINITE_TIMEOUT
-
Constructor Summary
ConstructorDescriptionPartitionedChannel
(int partitionCount) Instantiate based on a provided number of partitions and function resolving a partition key from theIntegrationMessageHeaderAccessor.CORRELATION_ID
message header.PartitionedChannel
(int partitionCount, Function<Message<?>, Object> partitionKeyFunction) Instantiate based on a provided number of partitions and function for partition key against the message. -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
protected PartitionedDispatcher
protected void
onInit()
Subclasses may implement this for initialization logic.void
setFailover
(boolean failover) Specify whether the channel's dispatcher should have failover enabled.void
setFailoverStrategy
(Predicate<Exception> failoverStrategy) Configure a strategy whether the channel's dispatcher should have failover enabled for the exception thrown.void
setLoadBalancingStrategy
(LoadBalancingStrategy loadBalancingStrategy) Provide aLoadBalancingStrategy
for thePartitionedDispatcher
.void
setThreadFactory
(ThreadFactory threadFactory) Set aThreadFactory
for executors per partitions.Methods inherited from class org.springframework.integration.channel.AbstractExecutorChannel
addInterceptor, addInterceptor, getIntegrationPatternType, 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
getComponentType, getFullChannelName, getIChannelInterceptorList, getInterceptors, getMetricsCaptor, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, send, send, setDatatypes, setLoggingEnabled, setMessageConverter, setObservationConvention, setShouldTrack
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, 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.support.management.IntegrationManagement
getManagedName, getManagedType, getThisAs, setManagedName, setManagedType
Methods inherited from interface org.springframework.messaging.support.InterceptableChannel
getInterceptors
Methods inherited from interface org.springframework.messaging.MessageChannel
send, send
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
PartitionedChannel
public PartitionedChannel(int partitionCount) Instantiate based on a provided number of partitions and function resolving a partition key from theIntegrationMessageHeaderAccessor.CORRELATION_ID
message header.- Parameters:
partitionCount
- the number of partitions in this channel. sent to this channel.
-
PartitionedChannel
Instantiate based on a provided number of partitions and function for partition key against the message.- Parameters:
partitionCount
- the number of partitions in this channel.partitionKeyFunction
- the function to resolve a partition key against the message sent to this channel.
-
-
Method Details
-
setThreadFactory
Set aThreadFactory
for executors per partitions. Propagated down to thePartitionedDispatcher
. Defaults to theCustomizableThreadFactory
based on the bean name of this channel plus-partition-thread-
.- Parameters:
threadFactory
- theThreadFactory
to use.
-
setFailover
public void setFailover(boolean failover) Specify whether the channel's dispatcher should have failover enabled. By default, it will. Set this value to 'false' to disable it.- Parameters:
failover
- The failover boolean.
-
setFailoverStrategy
Configure a strategy whether the channel's dispatcher should have failover enabled for the exception thrown. OverridessetFailover(boolean)
option. In other words: or this, or that option has to be set.- Parameters:
failoverStrategy
- The failover boolean.- Since:
- 6.3
-
setLoadBalancingStrategy
Provide aLoadBalancingStrategy
for thePartitionedDispatcher
.- Parameters:
loadBalancingStrategy
- The load balancing strategy implementation.
-
getDispatcher
- Specified by:
getDispatcher
in classAbstractSubscribableChannel
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classAbstractMessageChannel
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
- Specified by:
destroy
in interfaceIntegrationManagement
- Overrides:
destroy
in classAbstractMessageChannel
-