Class DefaultPulsarProducerFactory<T>

java.lang.Object
org.springframework.pulsar.core.DefaultPulsarProducerFactory<T>
Type Parameters:
T - producer type.
All Implemented Interfaces:
PulsarProducerFactory<T>
Direct Known Subclasses:
CachingPulsarProducerFactory

public class DefaultPulsarProducerFactory<T> extends Object implements PulsarProducerFactory<T>
Default implementation of PulsarProducerFactory.
Author:
Soby Chacko, Chris Bono, Alexander Preuß, Christophe Bornet
  • Constructor Details

    • DefaultPulsarProducerFactory

      public DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient)
      Construct a producer factory that uses a default topic resolver.
      Parameters:
      pulsarClient - the client used to create the producers
    • DefaultPulsarProducerFactory

      public DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient, @Nullable String defaultTopic)
      Construct a producer factory that uses a default topic resolver.
      Parameters:
      pulsarClient - the client used to create the producers
      defaultTopic - the default topic to use for the producers
    • DefaultPulsarProducerFactory

      public DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient, @Nullable String defaultTopic, @Nullable List<ProducerBuilderCustomizer<T>> defaultConfigCustomizers)
      Construct a producer factory that uses a default topic resolver.
      Parameters:
      pulsarClient - the client used to create the producers
      defaultTopic - the default topic to use for the producers
      defaultConfigCustomizers - the optional list of customizers to apply to the created producers
    • DefaultPulsarProducerFactory

      public DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient, @Nullable String defaultTopic, @Nullable List<ProducerBuilderCustomizer<T>> defaultConfigCustomizers, TopicResolver topicResolver)
      Construct a producer factory that uses the specified parameters.
      Parameters:
      pulsarClient - the client used to create the producers
      defaultTopic - the default topic to use for the producers
      defaultConfigCustomizers - the optional list of customizers to apply to the created producers
      topicResolver - the topic resolver to use
  • Method Details

    • createProducer

      public org.apache.pulsar.client.api.Producer<T> createProducer(org.apache.pulsar.client.api.Schema<T> schema, @Nullable String topic)
      Description copied from interface: PulsarProducerFactory
      Create a producer.
      Specified by:
      createProducer in interface PulsarProducerFactory<T>
      Parameters:
      schema - the schema of the messages to be sent
      topic - the topic the producer will send messages to or null to use the default topic
      Returns:
      the producer
    • createProducer

      public org.apache.pulsar.client.api.Producer<T> createProducer(org.apache.pulsar.client.api.Schema<T> schema, @Nullable String topic, @Nullable ProducerBuilderCustomizer<T> customizer)
      Description copied from interface: PulsarProducerFactory
      Create a producer.
      Specified by:
      createProducer in interface PulsarProducerFactory<T>
      Parameters:
      schema - the schema of the messages to be sent
      topic - the topic the producer will send messages to or null to use the default topic
      customizer - the optional customizer to apply to the producer builder
      Returns:
      the producer
    • createProducer

      public org.apache.pulsar.client.api.Producer<T> createProducer(org.apache.pulsar.client.api.Schema<T> schema, @Nullable String topic, @Nullable Collection<String> encryptionKeys, @Nullable List<ProducerBuilderCustomizer<T>> customizers)
      Description copied from interface: PulsarProducerFactory
      Create a producer.
      Specified by:
      createProducer in interface PulsarProducerFactory<T>
      Parameters:
      schema - the schema of the messages to be sent
      topic - the topic the producer will send messages to or null to use the default topic
      encryptionKeys - the encryption keys used by the producer, replacing the default encryption keys or null to use the default encryption keys. Beware that ProducerBuilder only has ProducerBuilder.addEncryptionKey(java.lang.String) and doesn't have methods to replace the encryption keys.
      customizers - the optional list of customizers to apply to the producer builder
      Returns:
      the producer
    • getPulsarClient

      public org.apache.pulsar.client.api.PulsarClient getPulsarClient()
      Description copied from interface: PulsarProducerFactory
      Get the Pulsar client that the producer factory uses to create producers.
      Specified by:
      getPulsarClient in interface PulsarProducerFactory<T>
      Returns:
      the Pulsar client that the producer factory uses to create producers
    • doCreateProducer

      protected org.apache.pulsar.client.api.Producer<T> doCreateProducer(org.apache.pulsar.client.api.Schema<T> schema, @Nullable String topic, @Nullable Collection<String> encryptionKeys, @Nullable List<ProducerBuilderCustomizer<T>> customizers)
      Create the actual producer.
      Parameters:
      schema - the schema of the messages to be sent
      topic - the topic the producer will send messages to or null to use the default topic
      encryptionKeys - the encryption keys used by the producer, replacing the default encryption keys or null to use the default encryption keys. Beware that ProducerBuilder only has ProducerBuilder.addEncryptionKey(java.lang.String) and doesn't have methods to replace the encryption keys.
      customizers - the optional list of customizers to apply to the producer builder
      Returns:
      the created producer
      Throws:
      org.apache.pulsar.client.api.PulsarClientException - if any error occurs
    • resolveTopicName

      protected String resolveTopicName(String userSpecifiedTopic)
    • getDefaultTopic

      public String getDefaultTopic()
      Description copied from interface: PulsarProducerFactory
      Get the default topic to use for all created producers.
      Specified by:
      getDefaultTopic in interface PulsarProducerFactory<T>
      Returns:
      the default topic to use for all created producers or null if no default set