Class AMQPHelper

java.lang.Object
fr.ght1pc9kc.testy.beat.messaging.AMQPHelper

public final class AMQPHelper extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    declareAndBindQueues(com.rabbitmq.client.Channel channel, String queueName, String exchangeQueueName)
    Declare queues for communication
    static 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 it
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 communication
      queueName - The queue name for rabbit communication
      exchangeQueueName - The exchange queue name for rabbit communication
      Throws:
      IOException - Exception if declaration failure
    • declareReplyQueue

      public static void declareReplyQueue(com.rabbitmq.client.Channel channel) throws IOException
      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

      public static void deleteReplyQueue(com.rabbitmq.client.Channel channel) throws IOException
      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 send
      senderOptions - The options used to send message
      exchangeQueueName - 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 send
      objectMapper - Mapper converting POJOs to byte content.
      senderOptions - The options used to send message
      exchangeQueueName - The exchange queue name
      timeout - The timeout duration before receiving a reply
      Returns:
      the result of sending ReviewResultMessage