Class RabbitUtil

java.lang.Object
com.github.workerframework.util.rabbitmq.RabbitUtil

public final class RabbitUtil extends Object
Utility wrapper methods for interacting with RabbitMQ.
  • Method Details

    • createRabbitConnection

      public static com.rabbitmq.client.Connection createRabbitConnection(String protocol, String host, int port, String user, String pass) throws IOException, TimeoutException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException
      Create a new RabbitMQ connection with a default configuration.
      Parameters:
      host - the host or IP running RabbitMQ
      port - the port that the RabbitMQ server is exposed on
      user - the username to use when authenticating with RabbitMQ
      pass - the password to use when authenticating with RabbitMQ
      Returns:
      a valid connection to RabbitMQ
      Throws:
      IOException - if the connection fails to establish
      TimeoutException - if the connection fails to establish
      URISyntaxException
      NoSuchAlgorithmException
      KeyManagementException
    • createRabbitConnection

      public static com.rabbitmq.client.Connection createRabbitConnection(RabbitConfiguration rc) throws IOException, TimeoutException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException
      Create a new RabbitMQ connection with custom settings.
      Parameters:
      rc - the connection config
      Returns:
      a valid connection to RabbitMQ
      Throws:
      IOException - if the connection fails to establish
      TimeoutException - if the connection fails to establish
      URISyntaxException
      NoSuchAlgorithmException
      KeyManagementException
    • createRabbitConnection

      public static com.rabbitmq.client.Connection createRabbitConnection(RabbitConfiguration rc, com.rabbitmq.client.ExceptionHandler exceptionHandler) throws IOException, TimeoutException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException
      Create a new RabbitMQ connection with custom settings.
      Parameters:
      rc - the connection config
      exceptionHandler - the exception handling implementation, a default handler will be used if null.
      Returns:
      a valid connection to RabbitMQ
      Throws:
      IOException - if the connection fails to establish
      TimeoutException - if the connection fails to establish
      URISyntaxException
      NoSuchAlgorithmException
      KeyManagementException
    • declareWorkerQueue

      public static void declareWorkerQueue(com.rabbitmq.client.Channel channel, String queueName) throws IOException
      Ensure a queue for a worker has been declared. Both a consumer *and* a publisher should call this before they attempt to use a worker queue for the first time.
      Parameters:
      channel - the channel to use to declare the queue
      queueName - the name of the worker queue
      Throws:
      IOException - if the queue is not valid and cannot be used, this is likely NOT retryable
    • declareWorkerQueue

      public static void declareWorkerQueue(com.rabbitmq.client.Channel channel, String queueName, int maxPriority, String queueType) throws IOException
      Ensure a queue for a worker has been declared. Both a consumer *and* a publisher should call this before they attempt to use a worker queue for the first time.
      Parameters:
      channel - the channel to use to declare the queue
      queueName - the name of the worker queue
      maxPriority - the maximum supported priority, pass 0 to disable priority
      queueType - the type of queue to be created eg: classic or quorum
      Throws:
      IOException - if the queue is not valid and cannot be used, this is likely NOT retryable
    • declareQueue

      public static void declareQueue(com.rabbitmq.client.Channel channel, String queueName, Durability dur, Exclusivity excl, EmptyAction act) throws IOException
      Declare a queue with arbitrary parameters and default queue properties.
      Parameters:
      channel - the channel to use to declare the queue
      queueName - the name of the queue
      dur - the durability setting of the queue
      excl - the exclusivity setting of the queue
      act - the empty action setting of the queue
      Throws:
      IOException - if the queue already exists AND the parameter settings do not match the existing queue
    • declareQueue

      public static void declareQueue(com.rabbitmq.client.Channel channel, String queueName, Durability dur, Exclusivity excl, EmptyAction act, Map<String,Object> queueProps) throws IOException
      Declare a queue with arbitrary parameters and properties.
      Parameters:
      channel - the channel to use to declare the queue
      queueName - the name of the queue
      dur - the durability setting of the queue
      excl - the exclusivity setting of the queue
      act - the empty action setting of the queue
      queueProps - the queue properties map
      Throws:
      IOException - if the queue already exists AND the parameter settings do not match the existing queue