Class PulsarTemplate<T>

java.lang.Object
org.springframework.pulsar.core.PulsarTemplate<T>
Type Parameters:
T - the message payload type
All Implemented Interfaces:
Aware, BeanNameAware, PulsarOperations<T>

public class PulsarTemplate<T> extends Object implements PulsarOperations<T>, BeanNameAware
A thread-safe template for executing high-level Pulsar operations.
Author:
Soby Chacko, Chris Bono, Alexander Preuß, Christophe Bornet
  • Constructor Details

    • PulsarTemplate

      public PulsarTemplate(PulsarProducerFactory<T> producerFactory)
      Construct a template instance.
      Parameters:
      producerFactory - the factory used to create the backing Pulsar producers.
    • PulsarTemplate

      public PulsarTemplate(PulsarProducerFactory<T> producerFactory, @Nullable List<org.apache.pulsar.client.api.interceptor.ProducerInterceptor> interceptors)
      Construct a template instance with optional interceptors.
      Parameters:
      producerFactory - the factory used to create the backing Pulsar producers.
      interceptors - the interceptors to add to the producer.
    • PulsarTemplate

      public PulsarTemplate(PulsarProducerFactory<T> producerFactory, @Nullable List<org.apache.pulsar.client.api.interceptor.ProducerInterceptor> interceptors, @Nullable io.micrometer.observation.ObservationRegistry observationRegistry, @Nullable PulsarTemplateObservationConvention observationConvention)
      Construct a template instance with optional interceptors and observation configuration.
      Parameters:
      producerFactory - the factory used to create the backing Pulsar producers
      interceptors - the optional list of interceptors to add to the producer
      observationRegistry - the registry to record observations with or null to not record observations
      observationConvention - the optional custom observation convention to use when recording observations
  • Method Details

    • send

      public org.apache.pulsar.client.api.MessageId send(T message) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: PulsarOperations
      Sends a message to the default topic in a blocking manner.
      Specified by:
      send in interface PulsarOperations<T>
      Parameters:
      message - the message to send
      Returns:
      the id assigned by the broker to the published message
      Throws:
      org.apache.pulsar.client.api.PulsarClientException - if an error occurs
    • send

      public org.apache.pulsar.client.api.MessageId send(@Nullable String topic, T message) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: PulsarOperations
      Sends a message to the specified topic in a blocking manner.
      Specified by:
      send in interface PulsarOperations<T>
      Parameters:
      topic - the topic to send the message to or null to send to the default topic
      message - the message to send
      Returns:
      the id assigned by the broker to the published message
      Throws:
      org.apache.pulsar.client.api.PulsarClientException - if an error occurs
    • sendAsync

      public CompletableFuture<org.apache.pulsar.client.api.MessageId> sendAsync(T message) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: PulsarOperations
      Sends a message to the default topic in a non-blocking manner.
      Specified by:
      sendAsync in interface PulsarOperations<T>
      Parameters:
      message - the message to send
      Returns:
      a future that holds the id assigned by the broker to the published message
      Throws:
      org.apache.pulsar.client.api.PulsarClientException - if an error occurs
    • sendAsync

      public CompletableFuture<org.apache.pulsar.client.api.MessageId> sendAsync(@Nullable String topic, T message) throws org.apache.pulsar.client.api.PulsarClientException
      Description copied from interface: PulsarOperations
      Sends a message to the specified topic in a non-blocking manner.
      Specified by:
      sendAsync in interface PulsarOperations<T>
      Parameters:
      topic - the topic to send the message to or null to send to the default topic
      message - the message to send
      Returns:
      a future that holds the id assigned by the broker to the published message
      Throws:
      org.apache.pulsar.client.api.PulsarClientException - if an error occurs
    • newMessage

      public PulsarOperations.SendMessageBuilder<T> newMessage(T message)
      Description copied from interface: PulsarOperations
      Create a builder for configuring and sending a message.
      Specified by:
      newMessage in interface PulsarOperations<T>
      Parameters:
      message - the payload of the message
      Returns:
      the builder to configure and send the message
    • setBeanName

      public void setBeanName(String beanName)
      Specified by:
      setBeanName in interface BeanNameAware
    • setSchema

      public void setSchema(org.apache.pulsar.client.api.Schema<T> schema)
      Set the schema to use on this template.
      Parameters:
      schema - provides the Schema used on this template