Interface RabbitMQClient


public interface RabbitMQClient
Author:
Nick Scavelli
  • Method Details

    • create

      static RabbitMQClient create(Vertx vertx)
      Create and return a client configured with the default options.
      Parameters:
      vertx - the vertx instance
      Returns:
      the client
    • create

      static RabbitMQClient create(Vertx vertx, RabbitMQOptions config)
      Create and return a client.
      Parameters:
      vertx - the vertx instance
      config - the client config
      Returns:
      the client
    • addConnectionEstablishedCallback

      void addConnectionEstablishedCallback(Handler<Promise<Void>> connectionEstablishedCallback)
      Set a callback to be called whenever a new connection is established. This callback must be idempotent - it will be called each time a connection is established, which may be multiple times against the same instance. Callbacks will be added to a list and called in the order they were added, the only way to remove callbacks is to create a new client. These callbacks should be used to establish any Rabbit MQ server objects that are required - exchanges, queues, bindings, etc. Each callback will receive a Promise that it must complete in order to pass control to the next callback (or back to the RabbitMQClient). If the callback fails the promise the RabbitMQClient will be unable to make a connection (it will attempt to connect again according to its retry configuration). If the promise is not completed or failed by a callback the RabbitMQClient will not start (it will hang indefinitely). Other methods on the client may be used in the callback - it is specifically expected that RabbitMQ objects will be declared, but the publish and consume methods must not be used. The connection established callbacks are particularly important with the RabbitMQPublisher and RabbitMQConsumer when they are used with servers that may failover to another instance of the server that does not have the same exchanges/queues configured on it. In this situation these callbacks are the only opportunity to create exchanges, queues and bindings before the client will attempt to use them when it re-establishes connection. If your failover cluster is guaranteed to have the appropriate objects already configured then it is not necessary to use the callbacks.
      Parameters:
      connectionEstablishedCallback - callback to be called whenever a new connection is established.
    • create

      static RabbitMQClient create(Vertx vertx, JsonObject config)
      Like create(Vertx, RabbitMQOptions) but with a JsonObject config object.
    • basicAck

      Future<Void> basicAck(long deliveryTag, boolean multiple)
      Acknowledge one or several received messages. Supply the deliveryTag from the AMQP.Basic.GetOk or AMQP.Basic.Deliver method containing the received message being acknowledged.
      See Also:
      • Channel.basicAck(long, boolean)
    • basicNack

      Future<Void> basicNack(long deliveryTag, boolean multiple, boolean requeue)
      Reject one or several received messages.
      See Also:
      • Channel.basicNack(long, boolean, boolean)
    • basicGet

      Future<RabbitMQMessage> basicGet(String queue, boolean autoAck)
      Retrieve a message from a queue using AMQP.Basic.Get
      See Also:
      • Channel.basicGet(String, boolean)
    • basicConsumer

      default Future<RabbitMQConsumer> basicConsumer(String queue)
      See Also:
    • basicConsumer

      Future<RabbitMQConsumer> basicConsumer(String queue, QueueOptions options)
      Create a consumer with the given options.
      Parameters:
      queue - the name of a queue
      options - options for queue
      Returns:
      a future completed with the operation status; if the operation succeeds you can begin to receive messages through an instance of RabbitMQConsumer
      See Also:
      • Channel.basicConsume(String, boolean, String, Consumer)
    • basicPublish

      Future<Void> basicPublish(String exchange, String routingKey, Buffer body)
      Publish a message. Publishing to a non-existent exchange will result in a channel-level protocol exception, which closes the channel. Invocations of Channel#basicPublish will eventually block if a resource-driven alarm is in effect.
      See Also:
      • Channel.basicPublish(String, String, AMQP.BasicProperties, byte[])
    • basicPublish

      Future<Void> basicPublish(String exchange, String routingKey, com.rabbitmq.client.BasicProperties properties, Buffer body)
      Publish a message. Publishing to a non-existent exchange will result in a channel-level protocol exception, which closes the channel. Invocations of Channel#basicPublish will eventually block if a resource-driven alarm is in effect.
      See Also:
      • Channel.basicPublish(String, String, AMQP.BasicProperties, byte[])
    • basicPublishWithDeliveryTag

      Future<Void> basicPublishWithDeliveryTag(String exchange, String routingKey, com.rabbitmq.client.BasicProperties properties, Buffer body, Handler<Long> deliveryTagHandler)
      Publish a message. Publishing to a non-existent exchange will result in a channel-level protocol exception, which closes the channel. Invocations of Channel#basicPublish will eventually block if a resource-driven alarm is in effect. The deliveryTagHandler will be called before the message is sent, which is necessary because the confirmation may arrive asynchronously before the resultHandler is called.
      Parameters:
      deliveryTagHandler - callback to capture the deliveryTag for this message. Note that this will be called synchronously in the context of the client before the result is known.
      See Also:
      • Channel.basicPublish(String, String, AMQP.BasicProperties, byte[])
    • addConfirmListener

      Future<ReadStream<RabbitMQConfirmation>> addConfirmListener(int maxQueueSize)
      Add a Confirm Listener to the channel. Note that this will automatically call confirmSelect, it is not necessary to call that too.
      Parameters:
      maxQueueSize - maximum size of the queue of confirmations
      Returns:
      a future completed with a stream of confirmations if the operation succeeds
      See Also:
      • Channel.addConfirmListener(ConfirmListener)
    • confirmSelect

      Future<Void> confirmSelect()
      Enables publisher acknowledgements on this channel. Can be called once during client initialisation. Calls to basicPublish() will have to be confirmed.
      See Also:
      • Channel.confirmSelect()
    • waitForConfirms

      Future<Void> waitForConfirms()
      Wait until all messages published since the last call have been either ack'd or nack'd by the broker. This will incur slight performance loss at the expense of higher write consistency. If desired, multiple calls to basicPublish() can be batched before confirming.
      See Also:
      • Channel.waitForConfirms()
    • waitForConfirms

      Future<Void> waitForConfirms(long timeout)
      Wait until all messages published since the last call have been either ack'd or nack'd by the broker; or until timeout elapses. If the timeout expires a TimeoutException is thrown.
      Parameters:
      timeout -
      See Also:
    • basicQos

      default Future<Void> basicQos(int prefetchCount)
      Request a specific prefetchCount "quality of service" settings for this channel.
      Parameters:
      prefetchCount - maximum number of messages that the server will deliver, 0 if unlimited
      See Also:
    • basicQos

      default Future<Void> basicQos(int prefetchCount, boolean global)
      Request a specific prefetchCount "quality of service" settings for this channel.
      Parameters:
      prefetchCount - maximum number of messages that the server will deliver, 0 if unlimited
      global - true if the settings should be applied to the entire channel rather than each consumer
      See Also:
    • basicQos

      Future<Void> basicQos(int prefetchSize, int prefetchCount, boolean global)
      Request specific "quality of service" settings. These settings impose limits on the amount of data the server will deliver to consumers before requiring acknowledgements. Thus they provide a means of consumer-initiated flow control.
      Parameters:
      prefetchSize - maximum amount of content (measured in octets) that the server will deliver, 0 if unlimited
      prefetchCount - maximum number of messages that the server will deliver, 0 if unlimited
      global - true if the settings should be applied to the entire channel rather than each consumer
      See Also:
      • AMQP.Basic.Qos
    • exchangeDeclare

      Future<Void> exchangeDeclare(String exchange, String type, boolean durable, boolean autoDelete)
      Declare an exchange.
      See Also:
      • Channel.exchangeDeclare(String, String, boolean, boolean, Map)
    • exchangeDeclare

      Future<Void> exchangeDeclare(String exchange, String type, boolean durable, boolean autoDelete, JsonObject config)
      Declare an exchange with additional parameters such as dead lettering, an alternate exchange or TTL.
      See Also:
      • Channel.exchangeDeclare(String, String, boolean, boolean, Map)
    • exchangeDelete

      Future<Void> exchangeDelete(String exchange)
      Delete an exchange, without regard for whether it is in use or not.
      See Also:
      • Channel.exchangeDelete(String)
    • exchangeBind

      Future<Void> exchangeBind(String destination, String source, String routingKey)
      Bind an exchange to an exchange.
      See Also:
      • Channel.exchangeBind(String, String, String)
    • exchangeBind

      Future<Void> exchangeBind(String destination, String source, String routingKey, Map<String,Object> arguments)
      Bind an exchange to an exchange.
      See Also:
      • Channel.exchangeBind(String, String, String, Map<String, Object>)
    • exchangeUnbind

      Future<Void> exchangeUnbind(String destination, String source, String routingKey)
      Unbind an exchange from an exchange.
      See Also:
      • Channel.exchangeUnbind(String, String, String)
    • exchangeUnbind

      Future<Void> exchangeUnbind(String destination, String source, String routingKey, Map<String,Object> arguments)
      Unbind an exchange from an exchange.
      See Also:
      • Channel.exchangeUnbind(String, String, String, Map<String, Object>)
    • queueDeclareAuto

      Future<JsonObject> queueDeclareAuto()
      Actively declare a server-named exclusive, autodelete, non-durable queue.
      See Also:
      • Channel.queueDeclare()
    • queueDeclare

      Future<com.rabbitmq.client.AMQP.Queue.DeclareOk> queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete)
      Declare a queue
      See Also:
      • Channel.queueDeclare(String, boolean, boolean, boolean, java.util.Map)
    • queueDeclare

      Future<com.rabbitmq.client.AMQP.Queue.DeclareOk> queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete, JsonObject config)
      Declare a queue with config options
      See Also:
      • Channel.queueDeclare(String, boolean, boolean, boolean, java.util.Map)
    • queueDelete

      Future<com.rabbitmq.client.AMQP.Queue.DeleteOk> queueDelete(String queue)
      Delete a queue, without regard for whether it is in use or has messages on it
      See Also:
      • Channel.queueDelete(String)
    • queueDeleteIf

      Future<com.rabbitmq.client.AMQP.Queue.DeleteOk> queueDeleteIf(String queue, boolean ifUnused, boolean ifEmpty)
      Delete a queue
      See Also:
      • Channel.queueDelete(String, boolean, boolean)
    • queueBind

      Future<Void> queueBind(String queue, String exchange, String routingKey)
      Bind a queue to an exchange
      See Also:
      • Channel.queueBind(String, String, String)
    • queueBind

      Future<Void> queueBind(String queue, String exchange, String routingKey, Map<String,Object> arguments)
      Bind a queue to an exchange
      See Also:
      • Channel.queueBind(String, String, String, Map<String, Object>)
    • queueUnbind

      Future<Void> queueUnbind(String queue, String exchange, String routingKey)
      Unbind a queue from an exchange
      See Also:
      • Channel.queueUnbind(String, String, String)
    • queueUnbind

      Future<Void> queueUnbind(String queue, String exchange, String routingKey, Map<String,Object> arguments)
      Unbind a queue from an exchange
      See Also:
      • Channel.queueUnbind(String, String, String, Map<String, Object>)
    • messageCount

      Future<Long> messageCount(String queue)
      Returns the number of messages in a queue ready to be delivered.
      See Also:
      • Channel.messageCount(String)
    • start

      Future<Void> start()
      Start the rabbitMQ client. Create the connection and the channel.
      See Also:
      • Connection.createChannel()
    • stop

      Future<Void> stop()
      Stop the rabbitMQ client. Close the connection and its channel.
      See Also:
      • Connection.close()
    • isConnected

      boolean isConnected()
      Check if a connection is open
      Returns:
      true when the connection is open, false otherwise
      See Also:
      • ShutdownNotifier.isOpen()
    • restartConnect

      Future<Void> restartConnect(int attempts)
      restart the rabbitMQ connect.
      Parameters:
      attempts - number of attempts
      Returns:
      a future notified when the operation is done with a result of the operation
    • isOpenChannel

      boolean isOpenChannel()
      Check if a channel is open
      Returns:
      true when the connection is open, false otherwise
      See Also:
      • ShutdownNotifier.isOpen()