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, Christian Tzolov, Ngoc Nhan
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRabbitStreamTemplate(com.rabbitmq.stream.Environment environment, String streamName) Construct an instance with the providedEnvironment. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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.MessageBuilderReturn the producer'sMessageBuilderto create native stream messages.Return the message converter.send(com.rabbitmq.stream.Message message) Send a native stream message.Send a Spring AMQP message.voidsetApplicationContext(ApplicationContext applicationContext) voidsetBeanName(String name) voidsetMessageConverter(MessageConverter messageConverter) Set a converter forconvertAndSend(Object)operations.voidsetObservationEnabled(boolean observationEnabled) Set to true to enable Micrometer observation.voidsetProducerCustomizer(ProducerCustomizer producerCustomizer) Used to customize theProducerBuilderbefore theProduceris built.voidsetStreamConverter(StreamMessageConverter streamConverter) Set a converter to convert fromMessagetoMessageforsend(Message)andconvertAndSend(Object)methods.voidsetSuperStreamRouting(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:
setApplicationContextin interfaceApplicationContextAware- Throws:
BeansException
-
setBeanName
- Specified by:
setBeanNamein 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 fromMessagetoMessageforsend(Message)andconvertAndSend(Object)methods.- Parameters:
streamConverter- the converter.
-
setProducerCustomizer
Used to customize theProducerBuilderbefore theProduceris 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:RabbitStreamOperationsReturn the message converter.- Specified by:
messageConverterin interfaceRabbitStreamOperations- Returns:
- the converter.
-
streamMessageConverter
Description copied from interface:RabbitStreamOperationsReturn the stream message converter.- Specified by:
streamMessageConverterin interfaceRabbitStreamOperations- Returns:
- the converter;
-
send
Description copied from interface:RabbitStreamOperationsSend a Spring AMQP message.- Specified by:
sendin interfaceRabbitStreamOperations- Parameters:
message- the message.- Returns:
- a future to indicate success/failure.
-
convertAndSend
Description copied from interface:RabbitStreamOperationsConvert to and send a Spring AMQP message.- Specified by:
convertAndSendin 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:RabbitStreamOperationsConvert to and send a Spring AMQP message. If aMessagePostProcessoris provided and returnsnull, the message is not sent and the future is completed withfalse.- Specified by:
convertAndSendin interfaceRabbitStreamOperations- Parameters:
message- the payload.mpp- a message post processor.- Returns:
- a future to indicate success/failure.
-
send
Description copied from interface:RabbitStreamOperationsSend a native stream message.- Specified by:
sendin 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:RabbitStreamOperationsReturn the producer'sMessageBuilderto create native stream messages.- Specified by:
messageBuilderin 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceRabbitStreamOperations
-