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 a 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 AbstractExecutorChannel
AbstractExecutorChannel.MessageHandlingTaskNested classes/interfaces inherited from class AbstractMessageChannel
AbstractMessageChannel.ChannelInterceptorListNested classes/interfaces inherited from interface IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields inherited from class AbstractExecutorChannel
dispatcher, executor, executorInterceptorsSize, maxSubscribersFields inherited from class AbstractMessageChannel
interceptors, metersFields inherited from class IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface MessageChannel
INDEFINITE_TIMEOUT -
Constructor Summary
ConstructorsConstructorDescriptionPartitionedChannel(int partitionCount) Instantiate based on a provided number of partitions and function resolving a partition key from theIntegrationMessageHeaderAccessor.CORRELATION_IDmessage header.PartitionedChannel(int partitionCount, Function<Message<?>, Object> partitionKeyFunction) Instantiate based on a provided number of partitions and function for a partition key against the message. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()protected PartitionedDispatcherprotected voidonInit()Subclasses may implement this for initialization logic.voidsetFailover(boolean failover) Specify whether the channel's dispatcher should have failover enabled.voidsetFailoverStrategy(Predicate<Exception> failoverStrategy) Configure a strategy whether the channel's dispatcher should have failover enabled for the exception thrown.voidsetLoadBalancingStrategy(@Nullable LoadBalancingStrategy loadBalancingStrategy) Provide aLoadBalancingStrategyfor thePartitionedDispatcher.voidsetThreadFactory(ThreadFactory threadFactory) Set aThreadFactoryfor executors per partitions.voidsetWorkerQueueSize(int workerQueueSize) Provide a size of the queue in the partition executor's worker.Methods inherited from class AbstractExecutorChannel
addInterceptor, addInterceptor, getIntegrationPatternType, hasExecutorInterceptors, removeInterceptor, removeInterceptor, setInterceptors, setMaxSubscribersMethods inherited from class AbstractSubscribableChannel
doSend, getSubscriberCount, subscribe, unsubscribeMethods inherited from class AbstractMessageChannel
getComponentType, getFullChannelName, getIChannelInterceptorList, getInterceptors, getMetricsCaptor, getOverrides, isApplicationRunning, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, send, send, setDatatypes, setLoggingEnabled, setMessageConverter, setObservationConvention, setShouldTrackMethods inherited from class 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, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface IntegrationManagement
getManagedName, getManagedType, getThisAs, setManagedName, setManagedTypeMethods inherited from interface InterceptableChannel
getInterceptorsMethods inherited from interface MessageChannel
send, sendMethods inherited from interface 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_IDmessage header.- Parameters:
partitionCount- the number of partitions in this channel.
-
PartitionedChannel
Instantiate based on a provided number of partitions and function for a 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 aThreadFactoryfor executors per partitions. Propagated down to thePartitionedDispatcher. Defaults to theCustomizableThreadFactorybased on the bean name of this channel plus-partition-thread-.- Parameters:
threadFactory- theThreadFactoryto 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 strategy predicate.- Since:
- 6.3
-
setLoadBalancingStrategy
Provide aLoadBalancingStrategyfor thePartitionedDispatcher.- Parameters:
loadBalancingStrategy- The load balancing strategy implementation.
-
setWorkerQueueSize
public void setWorkerQueueSize(int workerQueueSize) Provide a size of the queue in the partition executor's worker. Default to zero.- Parameters:
workerQueueSize- the size of the partition executor's worker queue.- Since:
- 6.4.10
-
getDispatcher
- Specified by:
getDispatcherin classAbstractSubscribableChannel
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classAbstractMessageChannel
-
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean- Specified by:
destroyin interfaceIntegrationManagement- Overrides:
destroyin classAbstractMessageChannel
-