Package com.saicone.delivery4j.broker
Class RabbitMQBroker
java.lang.Object
com.saicone.delivery4j.Broker
com.saicone.delivery4j.broker.RabbitMQBroker
RabbitMQ broker implementation to send data using queue and consumer via exchange.
-
Nested Class Summary
Nested classes/interfaces inherited from class com.saicone.delivery4j.Broker
Broker.Logger
-
Constructor Summary
ConstructorsConstructorDescriptionRabbitMQBroker
(@NotNull Connection connection, @NotNull String exchange) Constructs a rabbitmq broker with provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionThe current connection.static @NotNull RabbitMQBroker
of
(@NotNull String host, int port, @NotNull String username, @NotNull String password, @NotNull String virtualHost, @NotNull String exchange) Create a rabbitmq broker with provided parameters.static @NotNull RabbitMQBroker
Create a rabbitmq broker with provided parameters.static @NotNull RabbitMQBroker
Create a rabbitmq broker with provided parameters.protected void
onClose()
Method to run when broker closes.protected void
Method to run when byte data is being sent to broker.protected void
onStart()
Method to run when broker startsprotected void
onSubscribe
(@NotNull String... channels) Method to run when broker is being subscribed to new channels.protected void
onUnsubscribe
(@NotNull String... channels) Method to run when broker is being unsubscribed from channels.void
setReconnectionInterval
(int time, @NotNull TimeUnit unit) Set the reconnection interval that will be used on this redis broker instance.Methods inherited from class com.saicone.delivery4j.Broker
clear, close, getCodec, getConsumer, getExecutor, getLogger, getSubscribedChannels, isEnabled, onReceive, receive, send, setCodec, setConsumer, setEnabled, setExecutor, setLogger, start, subscribe, unsubscribe
-
Constructor Details
-
RabbitMQBroker
Constructs a rabbitmq broker with provided parameters.- Parameters:
connection
- the connection to interact with.exchange
- the pre-channel to use.
-
-
Method Details
-
of
@NotNull public static @NotNull RabbitMQBroker of(@NotNull @NotNull String url, @NotNull @NotNull String exchange) 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
@NotNull public static @NotNull RabbitMQBroker of(@NotNull @NotNull URI uri, @NotNull @NotNull String exchange) 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 -
onClose
protected void onClose()Description copied from class:Broker
Method to run when broker closes. -
onSubscribe
Description copied from class:Broker
Method to run when broker is being subscribed to new channels.- Overrides:
onSubscribe
in classBroker
- Parameters:
channels
- the channels name.
-
onUnsubscribe
Description copied from class:Broker
Method to run when broker is being unsubscribed from channels.- Overrides:
onUnsubscribe
in classBroker
- Parameters:
channels
- the channels name.
-
onSend
Description copied from class:Broker
Method to run when byte data is being sent to broker.- Specified by:
onSend
in classBroker
- Parameters:
channel
- the channel name.data
- the byte array data to send.- Throws:
IOException
- if any error occurs while sending the data.
-
setReconnectionInterval
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 thattime
is expressed in.
-
getConnection
The current connection.- Returns:
- a rabbitmq connection object.
-