Class AloRabbitMQSender<T>
- java.lang.Object
-
- io.atleon.rabbitmq.AloRabbitMQSender<T>
-
- Type Parameters:
T- outbound message body type (to be serialized)
- All Implemented Interfaces:
Closeable,AutoCloseable
public class AloRabbitMQSender<T> extends Object implements Closeable
A reactive RabbitMQ sender with at-least-once semantics for producing messages to exchanges in a RabbitMQ clusterAt most one instance of a
Senderis kept and can be closed upon invokingclose(). However, if after closing, more sent Publishers are subscribed to, a new Sender instance will be created and cached.
-
-
Field Summary
Fields Modifier and Type Field Description static StringBODY_SERIALIZER_CONFIGAn implementation ofBodySerializerused to serialize message bodiesstatic StringCONFIG_PREFIXPrefix used on all AloRabbitMQSender-specific configurations
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidclose(Object reason)Closes this sender and logs the provided reason.static <T> AloRabbitMQSender<T>create(RabbitMQConfigSource configSource)Creates a new AloRabbitMQSender from the providedRabbitMQConfigSourcestatic <T> AloRabbitMQSender<T>from(RabbitMQConfigSource configSource)Alias forcreate(RabbitMQConfigSource).Function<org.reactivestreams.Publisher<Alo<T>>,AloFlux<RabbitMQSenderResult<T>>>sendAloBodies(RabbitMQMessageCreator<T> messageCreator)AloFlux<RabbitMQSenderResult<T>>sendAloBodies(org.reactivestreams.Publisher<Alo<T>> aloBodies, RabbitMQMessageCreator<T> messageCreator)Sends a sequence ofAloitems referencing message bodies to be populated inRabbitMQMessages.AloFlux<RabbitMQSenderResult<RabbitMQMessage<T>>>sendAloMessages(org.reactivestreams.Publisher<Alo<RabbitMQMessage<T>>> aloMessages)Sends a sequence ofAloitems referencingRabbitMQMessagesFunction<org.reactivestreams.Publisher<T>,Flux<RabbitMQSenderResult<T>>>sendBodies(RabbitMQMessageCreator<T> messageCreator)Creates aFunctionthat can be used to transform a Publisher of RabbitMQ message bodies to a Publisher of the results of sending each message body.Flux<RabbitMQSenderResult<T>>sendBodies(org.reactivestreams.Publisher<T> bodies, RabbitMQMessageCreator<T> messageCreator)Sends a sequence of message bodies to be populated inRabbitMQMessages.Mono<RabbitMQSenderResult<RabbitMQMessage<T>>>sendMessage(RabbitMQMessage<T> message)Send a singleRabbitMQMessageFlux<RabbitMQSenderResult<RabbitMQMessage<T>>>sendMessages(org.reactivestreams.Publisher<RabbitMQMessage<T>> messages)Sends a sequence ofRabbitMQMessages
-
-
-
Field Detail
-
CONFIG_PREFIX
public static final String CONFIG_PREFIX
Prefix used on all AloRabbitMQSender-specific configurations- See Also:
- Constant Field Values
-
BODY_SERIALIZER_CONFIG
public static final String BODY_SERIALIZER_CONFIG
An implementation ofBodySerializerused to serialize message bodies- See Also:
- Constant Field Values
-
-
Method Detail
-
from
public static <T> AloRabbitMQSender<T> from(RabbitMQConfigSource configSource)
Alias forcreate(RabbitMQConfigSource). Will be deprecated in future release.
-
create
public static <T> AloRabbitMQSender<T> create(RabbitMQConfigSource configSource)
Creates a new AloRabbitMQSender from the providedRabbitMQConfigSource- Type Parameters:
T- The type of messages bodies sent by this sender- Parameters:
configSource- The reactive source ofRabbitMQConfig- Returns:
- A new AloRabbitMQSender
-
sendBodies
public Function<org.reactivestreams.Publisher<T>,Flux<RabbitMQSenderResult<T>>> sendBodies(RabbitMQMessageCreator<T> messageCreator)
Creates aFunctionthat can be used to transform a Publisher of RabbitMQ message bodies to a Publisher of the results of sending each message body. SeesendBodies(Publisher, RabbitMQMessageCreator)for further information.- Parameters:
messageCreator- A factory that createsRabbitMQMessages from message bodies- Returns:
- A
Functionuseful for Publisher transformations
-
sendBodies
public Flux<RabbitMQSenderResult<T>> sendBodies(org.reactivestreams.Publisher<T> bodies, RabbitMQMessageCreator<T> messageCreator)
Sends a sequence of message bodies to be populated inRabbitMQMessages. The destination exchange and routing key (if necessary) must be populated by the providedRabbitMQMessageCreator.The output of each sent message body is a
RabbitMQSenderResultcontaining the sent value.- Parameters:
bodies- A Publisher of RabbitMQ message bodiesmessageCreator- A factory that createsRabbitMQMessages from message bodies- Returns:
- a Publisher of the results of each sent message
-
sendMessage
public Mono<RabbitMQSenderResult<RabbitMQMessage<T>>> sendMessage(RabbitMQMessage<T> message)
Send a singleRabbitMQMessage- Parameters:
message- A message to send- Returns:
- A Publisher of the result of sending the message
-
sendMessages
public Flux<RabbitMQSenderResult<RabbitMQMessage<T>>> sendMessages(org.reactivestreams.Publisher<RabbitMQMessage<T>> messages)
Sends a sequence ofRabbitMQMessagesThe output of each sent message is a
RabbitMQSenderResultcontaining the sent message.- Parameters:
messages- A Publisher of messages to send- Returns:
- A Publisher of items referencing the result of each sent message
-
sendAloBodies
public Function<org.reactivestreams.Publisher<Alo<T>>,AloFlux<RabbitMQSenderResult<T>>> sendAloBodies(RabbitMQMessageCreator<T> messageCreator)
Creates aFunctionthat can be used to transform a Publisher ofAloitems referencing RabbitMQ message bodies to a Publisher of Alo items referencing the result of sending each message body. SeesendAloBodies(Publisher, RabbitMQMessageCreator)for further information.- Parameters:
messageCreator- A factory that createsRabbitMQMessages from message bodies- Returns:
- A
Functionuseful for Publisher transformations
-
sendAloBodies
public AloFlux<RabbitMQSenderResult<T>> sendAloBodies(org.reactivestreams.Publisher<Alo<T>> aloBodies, RabbitMQMessageCreator<T> messageCreator)
Sends a sequence ofAloitems referencing message bodies to be populated inRabbitMQMessages. The destination exchange and routing key (if necessary) must be populated by the providedRabbitMQMessageCreatorThe output of each sent message body is a
RabbitMQSenderResultcontaining the sent value. Each emitted item is anAloitem referencing aRabbitMQSenderResultand must be acknowledged or nacknowledged such that its processing can be marked complete at the origin of the message.- Parameters:
aloBodies- A Publisher of Alo items referencing RabbitMQ message bodiesmessageCreator- A factory that createsRabbitMQMessages from message bodies- Returns:
- a Publisher of Alo items referencing the result of each sent message
-
sendAloMessages
public AloFlux<RabbitMQSenderResult<RabbitMQMessage<T>>> sendAloMessages(org.reactivestreams.Publisher<Alo<RabbitMQMessage<T>>> aloMessages)
Sends a sequence ofAloitems referencingRabbitMQMessagesThe output of each sent message is a
RabbitMQSenderResultcontaining the sent message. Each emitted item is anAloitem referencing aRabbitMQSenderResultand must be acknowledged or nacknowledged such that its processing can be marked complete at the origin of the message.- Parameters:
aloMessages- A Publisher of Alo items referencing messages to send- Returns:
- A Publisher of Alo items referencing the result of each sent message
-
close
public void close(Object reason)
Closes this sender and logs the provided reason.- Parameters:
reason- The reason this sender is being closed
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-