Class QueueHandler.Singleton<K,​V>

  • Type Parameters:
    K - type of message-key; it should have a proper hash function in order to get O(1) access time, otherwise it may degrade to O(n)
    V - type of message-value
    Enclosing class:
    QueueHandler<K,​V>

    public static final class QueueHandler.Singleton<K,​V>
    extends Object
    Utility for building a singleton QueueHandler.

    Build it:

     private final Supplier> queueHandlerSupplier =
         QueueHandler.Singleton. builder()
             .queue(queueName())
             .connectionFactory(amqpConnectionFactory())
             .indexingBy(message -> message.content.yourKey)
             .consumingBy(
                 Unchecked.function(YourContentType::deserializeFromBytes))
             .publishingBy(YourContentType::serializeToBytes)
             .build()
             .supplier();
     
    and, later:
     public QueueHandler queueHandler() {
         return queueHandlerSupplier.get();
     }
     
    It is guaranteed that calling queueHandler() from any thread, will supply the same QueueHandler instance.

    The connection is internally managed and closed via a runtime shutdown hook.