public class GenericPublisher extends java.lang.Object implements MessagePublisher
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_RETRY_ATTEMPTS |
static int |
DEFAULT_RETRY_INTERVAL |
| Constructor and Description |
|---|
GenericPublisher(ConnectionProducer connectionProducer) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the publisher by closing its underlying channel.
|
protected <T extends java.lang.Exception> |
handleIoException(int attempt,
T exception)
Handles an exception depending on the already used attempts to send a message.
|
protected com.rabbitmq.client.Channel |
provideChannel()
Initializes a channel if there is not already an open channel.
|
void |
publish(java.lang.Object event,
net.reini.rabbitmq.cdi.PublisherConfiguration publisherConfiguration)
Publishes the given event using the given publisher configuration template.
|
public static final int DEFAULT_RETRY_ATTEMPTS
public static final int DEFAULT_RETRY_INTERVAL
public GenericPublisher(ConnectionProducer connectionProducer)
protected com.rabbitmq.client.Channel provideChannel()
throws java.io.IOException,
java.util.concurrent.TimeoutException
Initializes a channel if there is not already an open channel.
java.io.IOException - if the channel cannot be initializedjava.util.concurrent.TimeoutException - if the channel can not be opened within the timeout periodprotected <T extends java.lang.Exception> void handleIoException(int attempt,
T exception)
throws T extends java.lang.Exception
Handles an exception depending on the already used attempts to send a message. Also performs a soft reset of the currently used channel.
T - the type of exception being handledattempt - Current attempt countexception - The thrown exceptionT - if the maximum amount of attempts is exceededT extends java.lang.Exceptionpublic void publish(java.lang.Object event,
net.reini.rabbitmq.cdi.PublisherConfiguration publisherConfiguration)
throws java.io.IOException,
java.util.concurrent.TimeoutException
MessagePublisherPublishes the given event using the given publisher configuration template.
publish in interface MessagePublisherevent - the event being published to RabbitMQpublisherConfiguration - the default publisher configurationjava.io.IOException - if the channel can not be opened correctly or the actual send fails.java.util.concurrent.TimeoutException - if a timeout while sending occurspublic void close()
throws java.io.IOException,
java.util.concurrent.TimeoutException
Closes the publisher by closing its underlying channel.
close in interface java.lang.AutoCloseableclose in interface MessagePublisherjava.io.IOException - if the channel cannot be closed correctly. Usually occurs when the channel
is already closing or is already closed.java.util.concurrent.TimeoutException - if a timeout occurs while closing the publisher.