Class RabbitMQBroker

java.lang.Object
com.saicone.delivery4j.Broker
com.saicone.delivery4j.broker.RabbitMQBroker

public class RabbitMQBroker extends Broker
RabbitMQ broker implementation to send data using queue and consumer via exchange.
  • Constructor Details

    • RabbitMQBroker

      public RabbitMQBroker(@NotNull @NotNull Connection connection, @NotNull @NotNull String exchange)
      Constructs a rabbitmq broker with provided parameters.
      Parameters:
      connection - the connection to interact with.
      exchange - the pre-channel to use.
  • Method Details

    • of

      Create a rabbitmq broker with provided parameters.
      Parameters:
      url - the URL to connect with.
      exchange - the pre-channel to use.
      Returns:
      a newly generated rabbitmq broker.
    • of

      Create a rabbitmq broker with provided parameters.
      Parameters:
      uri - the URL object to connect with.
      exchange - the pre-channel to use.
      Returns:
      a newly generated rabbitmq broker.
    • of

      @NotNull public static @NotNull RabbitMQBroker of(@NotNull @NotNull String host, int port, @NotNull @NotNull String username, @NotNull @NotNull String password, @NotNull @NotNull String virtualHost, @NotNull @NotNull String exchange)
      Create a rabbitmq broker with provided parameters.
      Parameters:
      host - the host to connect.
      port - the port host.
      username - the username to validate authentication.
      password - the password to validate authentication.
      virtualHost - the virtual host.
      exchange - the pre-channel to use.
      Returns:
      a newly generated rabbitmq broker.
    • onStart

      protected void onStart()
      Description copied from class: Broker
      Method to run when broker starts
      Overrides:
      onStart in class Broker
    • onClose

      protected void onClose()
      Description copied from class: Broker
      Method to run when broker closes.
      Overrides:
      onClose in class Broker
    • onSubscribe

      protected void onSubscribe(@NotNull @NotNull String... channels)
      Description copied from class: Broker
      Method to run when broker is being subscribed to new channels.
      Overrides:
      onSubscribe in class Broker
      Parameters:
      channels - the channels name.
    • onUnsubscribe

      protected void onUnsubscribe(@NotNull @NotNull String... channels)
      Description copied from class: Broker
      Method to run when broker is being unsubscribed from channels.
      Overrides:
      onUnsubscribe in class Broker
      Parameters:
      channels - the channels name.
    • onSend

      protected void onSend(@NotNull @NotNull String channel, byte[] data) throws IOException
      Description copied from class: Broker
      Method to run when byte data is being sent to broker.
      Specified by:
      onSend in class Broker
      Parameters:
      channel - the channel name.
      data - the byte array data to send.
      Throws:
      IOException - if any error occurs while sending the data.
    • setReconnectionInterval

      public void setReconnectionInterval(int time, @NotNull @NotNull TimeUnit unit)
      Set the reconnection interval that will be used on this redis broker instance.
      Parameters:
      time - the time to wait until reconnection is performed.
      unit - the unit that time is expressed in.
    • getConnection

      @NotNull public @NotNull Connection getConnection()
      The current connection.
      Returns:
      a rabbitmq connection object.