Class RabbitMQAPI

java.lang.Object
com.kamikazejam.kamicommon.amqp.RabbitMQAPI

public class RabbitMQAPI extends Object
  • Method Details

    • stop

      public void stop()
      Stops the internal RabbitMQ Connection and Channel This API remains usable, but other methods may incur additional delays as the connection is re-established
    • basicAck

      public void basicAck(long deliveryTag, boolean multiple)
      Acknowledge a message by its delivery tag See Channel.basicAck(long, boolean)
    • publishMessage

      public void publishMessage(@NotNull @NotNull String queueName, @NotNull @NotNull String message)
      Publish a message to a queue - does NOT listen for a response
      Parameters:
      queueName - the name of the queue
      message - the message to publish
    • publishMessage

      public void publishMessage(@NotNull @NotNull String queueName, @NotNull com.rabbitmq.client.AMQP.BasicProperties props, @NotNull @NotNull String message)
      Publish a message to a queue (with properties) - does NOT listen for a response
      Parameters:
      queueName - the name of the queue
      props - additional message properties
      message - the message to publish
    • registerStdConsumer

      public void registerStdConsumer(@NotNull @NotNull String queueName, @NotNull @NotNull RabbitServerCallback callback)
      Register a standard consumer (default to auto-acknowledgement)
      Parameters:
      queueName - the name of the queue
      callback - the callback to consume messages
    • registerStdConsumer

      public void registerStdConsumer(@NotNull @NotNull String queueName, @NotNull @NotNull RabbitServerCallback callback, boolean autoAck)
      Register a standard consumer
      Parameters:
      queueName - the name of the queue
      callback - the callback to consume messages
      autoAck - if messages should be auto-acknowledged
    • publishRPC

      @NotNull public @NotNull CompletableFuture<String> publishRPC(@NotNull @NotNull RabbitRpcQueue queue, @NotNull @NotNull String message)
      Publish a 'RPC' style message and wait for a response
      Parameters:
      queue - The MQRpcQueue for client-server communication
      message - The message to publish
      Returns:
      a CompletableFuture which will be completed when the response is received
    • registerRpcConsumer

      public void registerRpcConsumer(@NotNull @NotNull RabbitRpcQueue queue, @NotNull @NotNull RabbitRpcCallback callback)
      Register a 'RPC' style consumer to listen for requests
      Parameters:
      queue - The MQRpcQueue for client-server communication
      callback - The callback to consume messages
    • registerFanConsumer

      public void registerFanConsumer(@NotNull @NotNull String queueName, @NotNull @NotNull String exchange, @NotNull @NotNull RabbitServerCallback callback)
      Register a standard consumer (default to auto-acknowledgement)
      Parameters:
      queueName - the name of the queue
      exchange - the callback to consume messages
      callback - the callback to consume messages
    • registerFanConsumer

      public void registerFanConsumer(@NotNull @NotNull String queueName, @NotNull @NotNull String exchange, @NotNull @NotNull RabbitServerCallback callback, boolean autoAck)
      Register a standard consumer
      Parameters:
      queueName - the name of the queue
      callback - the callback to consume messages
      autoAck - if messages should be auto-acknowledged
    • publishFanout

      public void publishFanout(@NotNull @NotNull String exchangeName, @NotNull @NotNull String message)
      Publish a message to a queue - does NOT listen for a response
      Parameters:
      exchangeName - the name of the exchange to publish to
      message - the message to publish
    • publishFanout

      public void publishFanout(@NotNull @NotNull String exchangeName, @NotNull com.rabbitmq.client.AMQP.BasicProperties props, @NotNull @NotNull String message)
      Publish a message to a queue (with properties) - does NOT listen for a response
      Parameters:
      exchangeName - the name of the queue
      props - additional message properties
      message - the message to publish
    • declareQueue

      public void declareQueue(@NotNull @NotNull String queueName)
      Declares a queue with a default TTL of 60 seconds (iff not declared already)
      Parameters:
      queueName - the name of the queue to declare
    • declareQueue

      public void declareQueue(@NotNull @NotNull String queueName, @Nullable @Nullable Long TTL_MS)
      Declares a queue with a specified TTL (iff not declared already)
      Parameters:
      queueName - the name of the queue to declare
      TTL_MS - the time-to-live of the queue (in milliseconds)
    • declareQueue

      public void declareQueue(@NotNull @NotNull String queueName, boolean durable, boolean exclusive, boolean autoDelete, @Nullable @Nullable Long TTL_MS)
      Declares a queue with a specified TTL (iff not declared already)
      Parameters:
      queueName - the name of the queue to declare
      durable - whether the queue should survive a broker restart
      exclusive - whether the queue should be exclusive to the connection
      autoDelete - whether the queue should be auto-deleted when no longer in use
      TTL_MS - the time-to-live of the queue (in milliseconds)
    • getChannel

      @Internal @NotNull public @NotNull com.rabbitmq.client.Channel getChannel()
      Get the underlying RabbitMQ Channel for direct access