Class DefaultMessageLockService
- java.lang.Object
-
- com.broadleafcommerce.common.messaging.service.DefaultMessageLockService
-
- All Implemented Interfaces:
MessageLockService
public class DefaultMessageLockService extends Object implements MessageLockService
Service that is responsible for managing locks for the processing of aMessage
. These locks are leveraged by theIdempotentMessageConsumptionService
to ensure that a message is only processed once per listener.- Author:
- Chris Kittrell (ckittrell)
-
-
Field Summary
Fields Modifier and Type Field Description static String
MESSAGE_IDEMPOTENCY_KEY
-
Constructor Summary
Constructors Constructor Description DefaultMessageLockService(ResourceLockRepository<?,?> resourceLockRepository)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ResourceLockRepository<?,?>
getResourceLockRepository()
String
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
releaseLock(String lockToken)
Releases the lock so that the relevant message can be processed again.
-
-
-
Field Detail
-
MESSAGE_IDEMPOTENCY_KEY
public static final String MESSAGE_IDEMPOTENCY_KEY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultMessageLockService
public DefaultMessageLockService(ResourceLockRepository<?,?> resourceLockRepository)
-
-
Method Detail
-
obtainLock
public String obtainLock(org.springframework.messaging.Message<?> message, String listenerName)
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
public void releaseLock(@Nullable String lockToken)
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
-
purgeLocks
public void purgeLocks(Duration messageLockTtl)
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.
-
getResourceLockRepository
protected ResourceLockRepository<?,?> getResourceLockRepository()
-
-