Class RabbitUtil
java.lang.Object
com.github.workerframework.util.rabbitmq.RabbitUtil
Utility wrapper methods for interacting with RabbitMQ.
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.rabbitmq.client.Connection
Create a new RabbitMQ connection with custom settings.static com.rabbitmq.client.Connection
createRabbitConnection
(RabbitConfiguration rc, com.rabbitmq.client.ExceptionHandler exceptionHandler) Create a new RabbitMQ connection with custom settings.static com.rabbitmq.client.Connection
createRabbitConnection
(String protocol, String host, int port, String user, String pass) Create a new RabbitMQ connection with a default configuration.static void
declareQueue
(com.rabbitmq.client.Channel channel, String queueName, Durability dur, Exclusivity excl, EmptyAction act) Declare a queue with arbitrary parameters and default queue properties.static void
declareQueue
(com.rabbitmq.client.Channel channel, String queueName, Durability dur, Exclusivity excl, EmptyAction act, Map<String, Object> queueProps) Declare a queue with arbitrary parameters and properties.static void
declareWorkerQueue
(com.rabbitmq.client.Channel channel, String queueName) Ensure a queue for a worker has been declared.static void
declareWorkerQueue
(com.rabbitmq.client.Channel channel, String queueName, int maxPriority, String queueType) Ensure a queue for a worker has been declared.
-
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 RabbitMQport
- the port that the RabbitMQ server is exposed onuser
- the username to use when authenticating with RabbitMQpass
- the password to use when authenticating with RabbitMQ- Returns:
- a valid connection to RabbitMQ
- Throws:
IOException
- if the connection fails to establishTimeoutException
- if the connection fails to establishURISyntaxException
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 establishTimeoutException
- if the connection fails to establishURISyntaxException
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 configexceptionHandler
- 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 establishTimeoutException
- if the connection fails to establishURISyntaxException
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 queuequeueName
- 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 queuequeueName
- the name of the worker queuemaxPriority
- the maximum supported priority, pass 0 to disable priorityqueueType
- 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 queuequeueName
- the name of the queuedur
- the durability setting of the queueexcl
- the exclusivity setting of the queueact
- 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 IOExceptionDeclare a queue with arbitrary parameters and properties.- Parameters:
channel
- the channel to use to declare the queuequeueName
- the name of the queuedur
- the durability setting of the queueexcl
- the exclusivity setting of the queueact
- the empty action setting of the queuequeueProps
- the queue properties map- Throws:
IOException
- if the queue already exists AND the parameter settings do not match the existing queue
-