Class RabbitStreamTemplate
java.lang.Object
org.springframework.rabbit.stream.producer.RabbitStreamTemplate
- All Implemented Interfaces:
AutoCloseable
,Aware
,BeanNameAware
,ApplicationContextAware
,RabbitStreamOperations
public class RabbitStreamTemplate
extends Object
implements RabbitStreamOperations, ApplicationContextAware, BeanNameAware
Default implementation of
RabbitStreamOperations
.- Since:
- 2.4
- Author:
- Gary Russell
-
Field Summary
-
Constructor Summary
ConstructorDescriptionRabbitStreamTemplate
(com.rabbitmq.stream.Environment environment, String streamName) Construct an instance with the providedEnvironment
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
convertAndSend
(Object message) Convert to and send a Spring AMQP message.convertAndSend
(Object message, MessagePostProcessor mpp) Convert to and send a Spring AMQP message.com.rabbitmq.stream.MessageBuilder
Return the producer'sMessageBuilder
to create native stream messages.Return the message converter.send
(com.rabbitmq.stream.Message message) Send a native stream message.Send a Spring AMQP message.void
setApplicationContext
(ApplicationContext applicationContext) void
setBeanName
(String name) void
setMessageConverter
(MessageConverter messageConverter) Set a converter forconvertAndSend(Object)
operations.void
setObservationEnabled
(boolean observationEnabled) Set to true to enable Micrometer observation.void
setProducerCustomizer
(ProducerCustomizer producerCustomizer) Used to customize theProducerBuilder
before theProducer
is built.void
setStreamConverter
(StreamMessageConverter streamConverter) Set a converter to convert fromMessage
toMessage
forsend(Message)
andconvertAndSend(Object)
methods.void
setSuperStreamRouting
(Function<com.rabbitmq.stream.Message, String> superStreamRouting) Add a routing function, making the stream a super stream.Return the stream message converter.
-
Field Details
-
logger
-
-
Constructor Details
-
RabbitStreamTemplate
Construct an instance with the providedEnvironment
.- Parameters:
environment
- the environment.streamName
- the stream name.
-
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
setBeanName
- Specified by:
setBeanName
in interfaceBeanNameAware
-
setSuperStreamRouting
Add a routing function, making the stream a super stream.- Parameters:
superStreamRouting
- the routing function.- Since:
- 3.0
-
setMessageConverter
Set a converter forconvertAndSend(Object)
operations.- Parameters:
messageConverter
- the converter.
-
setStreamConverter
Set a converter to convert fromMessage
toMessage
forsend(Message)
andconvertAndSend(Object)
methods.- Parameters:
streamConverter
- the converter.
-
setProducerCustomizer
Used to customize theProducerBuilder
before theProducer
is built.- Parameters:
producerCustomizer
- the customizer;
-
setObservationEnabled
public void setObservationEnabled(boolean observationEnabled) Set to true to enable Micrometer observation.- Parameters:
observationEnabled
- true to enable.- Since:
- 3.0.5
-
messageConverter
Description copied from interface:RabbitStreamOperations
Return the message converter.- Specified by:
messageConverter
in interfaceRabbitStreamOperations
- Returns:
- the converter.
-
streamMessageConverter
Description copied from interface:RabbitStreamOperations
Return the stream message converter.- Specified by:
streamMessageConverter
in interfaceRabbitStreamOperations
- Returns:
- the converter;
-
send
Description copied from interface:RabbitStreamOperations
Send a Spring AMQP message.- Specified by:
send
in interfaceRabbitStreamOperations
- Parameters:
message
- the message.- Returns:
- a future to indicate success/failure.
-
convertAndSend
Description copied from interface:RabbitStreamOperations
Convert to and send a Spring AMQP message.- Specified by:
convertAndSend
in interfaceRabbitStreamOperations
- Parameters:
message
- the payload.- Returns:
- a future to indicate success/failure.
-
convertAndSend
public CompletableFuture<Boolean> convertAndSend(Object message, @Nullable MessagePostProcessor mpp) Description copied from interface:RabbitStreamOperations
Convert to and send a Spring AMQP message. If aMessagePostProcessor
is provided and returnsnull
, the message is not sent and the future is completed withfalse
.- Specified by:
convertAndSend
in interfaceRabbitStreamOperations
- Parameters:
message
- the payload.mpp
- a message post processor.- Returns:
- a future to indicate success/failure.
-
send
Description copied from interface:RabbitStreamOperations
Send a native stream message.- Specified by:
send
in interfaceRabbitStreamOperations
- Parameters:
message
- the message.- Returns:
- a future to indicate success/failure.
- See Also:
-
messageBuilder
public com.rabbitmq.stream.MessageBuilder messageBuilder()Description copied from interface:RabbitStreamOperations
Return the producer'sMessageBuilder
to create native stream messages.- Specified by:
messageBuilder
in interfaceRabbitStreamOperations
- Returns:
- the builder.
- See Also:
-
close
public void close()Close the underlying producer; a new producer will be created on the next operation that requires one.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceRabbitStreamOperations
-