Class DefaultMessageLockService
java.lang.Object
com.broadleafcommerce.common.messaging.service.DefaultMessageLockService
- All Implemented Interfaces:
MessageLockService
Service that is responsible for managing locks for the processing of a
Message
. These
locks are leveraged by the IdempotentMessageConsumptionService
to ensure that a message
is only processed once per listener.- Author:
- Chris Kittrell (ckittrell)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
protected MessageLockProperties
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultMessageLockService
(ResourceLockRepository<?, ?> resourceLockRepository) -
Method Summary
Modifier and TypeMethodDescriptionvoid
finishLock
(String lockToken) Update the status of the lock to indicate the associated process is complete.protected ResourceLockRepository<?,
?> obtainLock
(org.springframework.messaging.Message<?> message, String listenerName) void
purgeLocks
(Duration messageLockTtl) Deletes all message locks that are out of date according to themessageLockTtl
.void
purgeLocks
(Duration messageLockTtl, Set<String> additionalLockTypes) Deletes all message locks that are out of date according to themessageLockTtl
.void
releaseLock
(String lockToken) Releases the lock so that the relevant message can be processed again.void
setProperties
(MessageLockProperties properties) protected boolean
validateTakeoverRequest
(String listenerName)
-
Field Details
-
MESSAGE_IDEMPOTENCY_KEY
- See Also:
-
MESSAGE_LOCK_COMPLETION_STATE
- See Also:
-
properties
-
-
Constructor Details
-
DefaultMessageLockService
-
-
Method Details
-
obtainLock
Description copied from interface:MessageLockService
- Specified by:
obtainLock
in interfaceMessageLockService
- Parameters:
message
- The message that is to be lockedlistenerName
- The name of the message listener. This value can be used to distinguish this message consumption from that of a different message listener.- Returns:
- A unique token that can later be used to release the lock
-
releaseLock
Description copied from interface:MessageLockService
Releases the lock so that the relevant message can be processed again. We primarily want to use this method when an unexpected error is encountered while processing the message.- Specified by:
releaseLock
in interfaceMessageLockService
- Parameters:
lockToken
- The unique token that was provided when the lock was obtained
-
finishLock
Description copied from interface:MessageLockService
Update the status of the lock to indicate the associated process is complete.- Specified by:
finishLock
in interfaceMessageLockService
- Parameters:
lockToken
- The unique token that was provided when the lock was obtained
-
purgeLocks
Description copied from interface:MessageLockService
Deletes all message locks that are out of date according to themessageLockTtl
.- Specified by:
purgeLocks
in interfaceMessageLockService
- Parameters:
messageLockTtl
- How long the lock should be held. If the lock is too old, then it should be removed.
-
purgeLocks
Description copied from interface:MessageLockService
Deletes all message locks that are out of date according to themessageLockTtl
. By default, this method always deletes the locks that haveJpaResourceLock.getTypeAlias()
equal to "Message".- Specified by:
purgeLocks
in interfaceMessageLockService
- Parameters:
messageLockTtl
- How long the lock should be held. If the lock is too old, then it should be removed.additionalLockTypes
- Additional types of locks to be removed.
-
validateTakeoverRequest
-
getResourceLockRepository
-
setProperties
-