public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageProducingHandler implements org.springframework.beans.factory.DisposableBean, IntegrationEvaluationContextAware, org.springframework.context.ApplicationEventPublisherAware
MessageStore
. This class takes care of correlated groups of messages
that can be completed in batches. It is useful for custom implementation of MessageHandlers that require correlation
and is used as a base class for Aggregator - AggregatingMessageHandler
and
Resequencer - ResequencingMessageHandler
,
or custom implementations requiring correlation.
To customize this handler inject CorrelationStrategy
,
ReleaseStrategy
, and MessageGroupProcessor
implementations as
you require.
By default the CorrelationStrategy
will be a
HeaderAttributeCorrelationStrategy
and the ReleaseStrategy
will be a
SequenceSizeReleaseStrategy
.
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractCorrelatingMessageHandler.SequenceAwareMessageGroup |
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_SEND_TIMEOUT |
protected MessageGroupStore |
messageStore |
messagingTemplate
Constructor and Description |
---|
AbstractCorrelatingMessageHandler(MessageGroupProcessor processor) |
AbstractCorrelatingMessageHandler(MessageGroupProcessor processor,
MessageGroupStore store) |
AbstractCorrelatingMessageHandler(MessageGroupProcessor processor,
MessageGroupStore store,
CorrelationStrategy correlationStrategy,
ReleaseStrategy releaseStrategy) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
afterRelease(MessageGroup group,
java.util.Collection<org.springframework.messaging.Message<?>> completedMessages)
Allows you to provide additional logic that needs to be performed after the MessageGroup was released.
|
protected java.util.Collection<org.springframework.messaging.Message<?>> |
completeGroup(org.springframework.messaging.Message<?> message,
java.lang.Object correlationKey,
MessageGroup group) |
protected void |
completeGroup(java.lang.Object correlationKey,
MessageGroup group) |
void |
destroy() |
protected void |
expireGroup(java.lang.Object correlationKey,
MessageGroup group) |
protected int |
findLastReleasedSequenceNumber(java.lang.Object groupId,
java.util.Collection<org.springframework.messaging.Message<?>> partialSequence) |
protected void |
forceComplete(MessageGroup group) |
java.lang.String |
getComponentType()
Subclasses may implement this method to provide component type information.
|
protected CorrelationStrategy |
getCorrelationStrategy() |
protected org.springframework.messaging.MessageChannel |
getDiscardChannel() |
protected java.lang.String |
getDiscardChannelName() |
protected org.springframework.expression.EvaluationContext |
getEvaluationContext() |
protected java.util.Map<java.util.UUID,java.util.concurrent.ScheduledFuture<?>> |
getExpireGroupScheduledFutures() |
protected org.springframework.expression.Expression |
getGroupTimeoutExpression() |
protected LockRegistry |
getLockRegistry() |
protected MessageGroupStore |
getMessageStore() |
protected long |
getMinimumTimeoutForEmptyGroups() |
protected MessageGroupProcessor |
getOutputProcessor() |
protected ReleaseStrategy |
getReleaseStrategy() |
protected void |
handleMessageInternal(org.springframework.messaging.Message<?> message) |
protected boolean |
isLockRegistrySet() |
protected boolean |
isReleasePartialSequences() |
protected boolean |
isSendPartialResultOnExpiry() |
protected boolean |
isSequenceAware() |
protected java.lang.Long |
obtainGroupTimeout(MessageGroup group) |
protected void |
onInit()
Subclasses may implement this for initialization logic.
|
protected void |
sendReplies(java.lang.Object processorResult,
org.springframework.messaging.Message message) |
protected void |
sendReplyMessage(java.lang.Object reply,
java.lang.Object replyChannel) |
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) |
void |
setCorrelationStrategy(CorrelationStrategy correlationStrategy) |
void |
setDiscardChannel(org.springframework.messaging.MessageChannel discardChannel) |
void |
setDiscardChannelName(java.lang.String discardChannelName) |
protected void |
setExpireGroupsUponTimeout(boolean expireGroupsUponTimeout)
Expire (completely remove) a group if it is completed due to timeout.
|
void |
setGroupTimeoutExpression(org.springframework.expression.Expression groupTimeoutExpression) |
void |
setIntegrationEvaluationContext(org.springframework.expression.EvaluationContext evaluationContext) |
void |
setLockRegistry(LockRegistry lockRegistry) |
void |
setMessageStore(MessageGroupStore store) |
void |
setMinimumTimeoutForEmptyGroups(long minimumTimeoutForEmptyGroups)
By default, when a MessageGroupStoreReaper is configured to expire partial
groups, empty groups are also removed.
|
void |
setReleasePartialSequences(boolean releasePartialSequences) |
void |
setReleaseStrategy(ReleaseStrategy releaseStrategy) |
void |
setSendPartialResultOnExpiry(boolean sendPartialResultOnExpiry) |
void |
setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler) |
protected boolean |
shouldSendMultipleReplies(java.lang.Iterable<?> iter) |
protected MessageGroup |
store(java.lang.Object correlationKey,
org.springframework.messaging.Message<?> message) |
protected void |
verifyResultCollectionConsistsOfMessages(java.util.Collection<?> elements) |
getOutputChannel, setOutputChannel, setOutputChannelName, setSendTimeout
getOrder, handleMessage, setOrder, setShouldTrack
afterPropertiesSet, getApplicationContext, getApplicationContextId, getBeanFactory, getComponentName, getConversionService, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, setApplicationContext, setBeanFactory, setBeanName, setComponentName, setConversionService, setMessageBuilderFactory, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getComponentName
public static final long DEFAULT_SEND_TIMEOUT
protected volatile MessageGroupStore messageStore
public AbstractCorrelatingMessageHandler(MessageGroupProcessor processor, MessageGroupStore store, CorrelationStrategy correlationStrategy, ReleaseStrategy releaseStrategy)
public AbstractCorrelatingMessageHandler(MessageGroupProcessor processor, MessageGroupStore store)
public AbstractCorrelatingMessageHandler(MessageGroupProcessor processor)
public void setLockRegistry(LockRegistry lockRegistry)
public void setMessageStore(MessageGroupStore store)
public void setCorrelationStrategy(CorrelationStrategy correlationStrategy)
public void setReleaseStrategy(ReleaseStrategy releaseStrategy)
public void setGroupTimeoutExpression(org.springframework.expression.Expression groupTimeoutExpression)
public void setIntegrationEvaluationContext(org.springframework.expression.EvaluationContext evaluationContext)
setIntegrationEvaluationContext
in interface IntegrationEvaluationContextAware
public void setTaskScheduler(org.springframework.scheduling.TaskScheduler taskScheduler)
setTaskScheduler
in class IntegrationObjectSupport
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface org.springframework.context.ApplicationEventPublisherAware
protected void onInit() throws java.lang.Exception
IntegrationObjectSupport
onInit
in class AbstractMessageProducingHandler
java.lang.Exception
- Any exception.public void setDiscardChannel(org.springframework.messaging.MessageChannel discardChannel)
public void setDiscardChannelName(java.lang.String discardChannelName)
public void setSendPartialResultOnExpiry(boolean sendPartialResultOnExpiry)
public void setMinimumTimeoutForEmptyGroups(long minimumTimeoutForEmptyGroups)
minimumTimeoutForEmptyGroups
- The minimum timeout.public void setReleasePartialSequences(boolean releasePartialSequences)
protected void setExpireGroupsUponTimeout(boolean expireGroupsUponTimeout)
afterRelease(MessageGroup, Collection)
.
Default true.expireGroupsUponTimeout
- the expireGroupsOnTimeout to setpublic java.lang.String getComponentType()
IntegrationObjectSupport
getComponentType
in interface NamedComponent
getComponentType
in class AbstractMessageHandler
protected MessageGroupStore getMessageStore()
protected java.util.Map<java.util.UUID,java.util.concurrent.ScheduledFuture<?>> getExpireGroupScheduledFutures()
protected MessageGroupProcessor getOutputProcessor()
protected CorrelationStrategy getCorrelationStrategy()
protected ReleaseStrategy getReleaseStrategy()
protected org.springframework.messaging.MessageChannel getDiscardChannel()
protected java.lang.String getDiscardChannelName()
protected boolean isSendPartialResultOnExpiry()
protected boolean isSequenceAware()
protected LockRegistry getLockRegistry()
protected boolean isLockRegistrySet()
protected long getMinimumTimeoutForEmptyGroups()
protected boolean isReleasePartialSequences()
protected org.springframework.expression.Expression getGroupTimeoutExpression()
protected org.springframework.expression.EvaluationContext getEvaluationContext()
protected void handleMessageInternal(org.springframework.messaging.Message<?> message) throws java.lang.Exception
handleMessageInternal
in class AbstractMessageHandler
java.lang.Exception
protected abstract void afterRelease(MessageGroup group, java.util.Collection<org.springframework.messaging.Message<?>> completedMessages)
group
- The group.completedMessages
- The completed messages.protected void forceComplete(MessageGroup group)
protected int findLastReleasedSequenceNumber(java.lang.Object groupId, java.util.Collection<org.springframework.messaging.Message<?>> partialSequence)
protected MessageGroup store(java.lang.Object correlationKey, org.springframework.messaging.Message<?> message)
protected void expireGroup(java.lang.Object correlationKey, MessageGroup group)
protected void completeGroup(java.lang.Object correlationKey, MessageGroup group)
protected java.util.Collection<org.springframework.messaging.Message<?>> completeGroup(org.springframework.messaging.Message<?> message, java.lang.Object correlationKey, MessageGroup group)
protected void verifyResultCollectionConsistsOfMessages(java.util.Collection<?> elements)
protected void sendReplies(java.lang.Object processorResult, org.springframework.messaging.Message message)
protected void sendReplyMessage(java.lang.Object reply, java.lang.Object replyChannel)
protected boolean shouldSendMultipleReplies(java.lang.Iterable<?> iter)
protected java.lang.Long obtainGroupTimeout(MessageGroup group)
public void destroy() throws java.lang.Exception
destroy
in interface org.springframework.beans.factory.DisposableBean
java.lang.Exception