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 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 Details

  • Constructor Details

    • DefaultMessageLockService

      public DefaultMessageLockService(ResourceLockRepository<?,?> resourceLockRepository)
  • Method Details

    • obtainLock

      public String obtainLock(org.springframework.messaging.Message<?> message, String listenerName)
      Description copied from interface: MessageLockService
      Creates a JpaResourceLock based on the contents of the provided Message and listenerName.
      Specified by:
      obtainLock in interface MessageLockService
      Parameters:
      message - The message that is to be locked
      listenerName - 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 interface MessageLockService
      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 the messageLockTtl.
      Specified by:
      purgeLocks in interface MessageLockService
      Parameters:
      messageLockTtl - How long the lock should be held. If the lock is too old, then it should be removed.
    • purgeLocks

      public void purgeLocks(Duration messageLockTtl, Set<String> additionalLockTypes)
      Description copied from interface: MessageLockService
      Deletes all message locks that are out of date according to the messageLockTtl. By default, this method always deletes the locks that have JpaResourceLock.getTypeAlias() equal to "Message".
      Specified by:
      purgeLocks in interface MessageLockService
      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.
    • getResourceLockRepository

      protected ResourceLockRepository<?,?> getResourceLockRepository()