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(com.rabbitmq.client.ConnectionFactory connectionFactory) |
| 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,
EventPublisher.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(com.rabbitmq.client.ConnectionFactory connectionFactory)
protected com.rabbitmq.client.Channel provideChannel()
throws java.io.IOException,
java.util.concurrent.TimeoutException
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
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,
EventPublisher.PublisherConfiguration publisherConfiguration)
throws java.io.IOException,
java.util.concurrent.TimeoutException
MessagePublisherpublish 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
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.