Class AMQPHelper
java.lang.Object
fr.ght1pc9kc.testy.beat.messaging.AMQPHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
declareAndBindQueues
(com.rabbitmq.client.Channel channel, String queueName, String exchangeQueueName) Declare queues for communicationstatic void
declareConsumer
(com.rabbitmq.client.Channel channel, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Queue<com.rabbitmq.client.Delivery> messages, String queueName, @Nullable Object replyMessage) Declare a consumer on the given queue.static void
declareReplyQueue
(com.rabbitmq.client.Channel channel) Declare the default reply-queue.static void
deleteReplyQueue
(com.rabbitmq.client.Channel channel) Delete the default reply-to queue.static reactor.core.publisher.Mono<com.rabbitmq.client.Delivery>
emitWithReply
(Object message, com.fasterxml.jackson.databind.ObjectMapper objectMapper, reactor.rabbitmq.SenderOptions senderOptions, String exchangeQueueName, Duration timeout) Declare a message to send into rabbit communication and send itstatic reactor.core.publisher.Mono<com.rabbitmq.client.Delivery>
emitWithReply
(Object message, reactor.rabbitmq.SenderOptions senderOptions, String exchangeQueueName) Declare a message to send into rabbit communication and send it
-
Method Details
-
declareAndBindQueues
public static void declareAndBindQueues(com.rabbitmq.client.Channel channel, String queueName, String exchangeQueueName) throws IOException Declare queues for communication- Parameters:
channel
- The channel object used for communicationqueueName
- The queue name for rabbit communicationexchangeQueueName
- The exchange queue name for rabbit communication- Throws:
IOException
- Exception if declaration failure
-
declareReplyQueue
Declare the default reply-queue. This queue is declared separately because we do not want to auto-delete it (otherwise only one RPC request can be sent by test).- Parameters:
channel
- Channel to declare the queue.- Throws:
IOException
- Error when declaring the queue.
-
deleteReplyQueue
Delete the default reply-to queue. Do not auto delete the reply queue otherwise only one RPC message can be sent (the reply queue is deleted before sending the next one). This causes an error when trying to emit many messages during the same unit test.- Parameters:
channel
- Channel to delete the queue.- Throws:
IOException
- Error when deleting the queue.
-
declareConsumer
public static void declareConsumer(com.rabbitmq.client.Channel channel, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Queue<com.rabbitmq.client.Delivery> messages, String queueName, @Nullable @Nullable Object replyMessage) Declare a consumer on the given queue.- Parameters:
channel
- Channel of the AMQP broker.objectMapper
- Jackson mapper to convert deliveries to object.messages
- Queue where the messages are put.queueName
- Name of the consumed queue.replyMessage
- Content of the response body.
-
emitWithReply
public static reactor.core.publisher.Mono<com.rabbitmq.client.Delivery> emitWithReply(Object message, reactor.rabbitmq.SenderOptions senderOptions, String exchangeQueueName) Declare a message to send into rabbit communication and send it- Parameters:
message
- The rabbit message to sendsenderOptions
- The options used to send messageexchangeQueueName
- The exchange queue name- Returns:
- the result of sending ReviewResultMessage
-
emitWithReply
public static reactor.core.publisher.Mono<com.rabbitmq.client.Delivery> emitWithReply(Object message, com.fasterxml.jackson.databind.ObjectMapper objectMapper, reactor.rabbitmq.SenderOptions senderOptions, String exchangeQueueName, Duration timeout) Declare a message to send into rabbit communication and send it- Parameters:
message
- The rabbit message to sendobjectMapper
- Mapper converting POJOs to byte content.senderOptions
- The options used to send messageexchangeQueueName
- The exchange queue nametimeout
- The timeout duration before receiving a reply- Returns:
- the result of sending ReviewResultMessage
-