Class QueueHandler.Singleton<K,V>
- java.lang.Object
-
- dev.aherscu.qa.jgiven.rabbitmq.utils.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
and, later:> queueHandlerSupplier = QueueHandler.Singleton. builder() .queue(queueName()) .connectionFactory(amqpConnectionFactory()) .indexingBy(message -> message.content.yourKey) .consumingBy( Unchecked.function(YourContentType::deserializeFromBytes)) .publishingBy(YourContentType::serializeToBytes) .build() .supplier(); public QueueHandler
It is guaranteed that callingqueueHandler() { return queueHandlerSupplier.get(); } queueHandler()
from any thread, will supply the same QueueHandler instance.The connection is internally managed and closed via a runtime shutdown hook.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QueueHandler.Singleton.SingletonBuilder<K,V>
-
Field Summary
Fields Modifier and Type Field Description com.rabbitmq.client.ConnectionFactory
connectionFactory
Function<byte[],V>
consumingBy
Function<Message<V>,K>
indexingBy
Function<V,byte[]>
publishingBy
String
queue
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <K,V>
QueueHandler.Singleton.SingletonBuilder<K,V>builder()
Supplier<QueueHandler<K,V>>
supplier()
-
-
-
Field Detail
-
connectionFactory
public final com.rabbitmq.client.ConnectionFactory connectionFactory
-
queue
public final String queue
-
-
Method Detail
-
supplier
public Supplier<QueueHandler<K,V>> supplier()
- Returns:
- a memoized supplier of QueueHandler
-
builder
public static <K,V> QueueHandler.Singleton.SingletonBuilder<K,V> builder()
-
-