Package org.springframework.pulsar.core
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
Default implementation of
PulsarProducerFactory.-
Constructor Summary
ConstructorsConstructorDescriptionDefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient) Construct a producer factory that uses a default topic resolver.DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient, String defaultTopic) Construct a producer factory that uses a default topic resolver.DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient, String defaultTopic, List<ProducerBuilderCustomizer<T>> defaultConfigCustomizers) Construct a producer factory that uses a default topic resolver.DefaultPulsarProducerFactory(org.apache.pulsar.client.api.PulsarClient pulsarClient, String defaultTopic, List<ProducerBuilderCustomizer<T>> defaultConfigCustomizers, TopicResolver topicResolver) Construct a producer factory that uses the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.pulsar.client.api.Producer<T>createProducer(org.apache.pulsar.client.api.Schema<T> schema, String topic) Create a producer.org.apache.pulsar.client.api.Producer<T>createProducer(org.apache.pulsar.client.api.Schema<T> schema, String topic, Collection<String> encryptionKeys, List<ProducerBuilderCustomizer<T>> customizers) Create a producer.org.apache.pulsar.client.api.Producer<T>createProducer(org.apache.pulsar.client.api.Schema<T> schema, String topic, ProducerBuilderCustomizer<T> customizer) Create a producer.protected org.apache.pulsar.client.api.Producer<T>doCreateProducer(org.apache.pulsar.client.api.Schema<T> schema, String topic, Collection<String> encryptionKeys, List<ProducerBuilderCustomizer<T>> customizers) Create the actual producer.Get the default topic to use for all created producers.org.apache.pulsar.client.api.PulsarClientGet the Pulsar client that the producer factory uses to create producers.protected StringresolveTopicName(String userSpecifiedTopic) voidsetTopicBuilder(PulsarTopicBuilder topicBuilder) Non-fully-qualified topic names specified on the created producers will be automatically fully-qualified with a default prefix (domain://tenant/namespace) according to the specified topic builder.
-
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 producersdefaultTopic- 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 producersdefaultTopic- the default topic to use for the producersdefaultConfigCustomizers- 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 producersdefaultTopic- the default topic to use for the producersdefaultConfigCustomizers- the optional list of customizers to apply to the created producerstopicResolver- the topic resolver to use
-
-
Method Details
-
setTopicBuilder
Non-fully-qualified topic names specified on the created producers will be automatically fully-qualified with a default prefix (domain://tenant/namespace) according to the specified topic builder.- Parameters:
topicBuilder- the topic builder used to fully qualify topic names or null to not fully qualify topic names- Since:
- 1.2.0
-
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:PulsarProducerFactoryCreate a producer.- Specified by:
createProducerin interfacePulsarProducerFactory<T>- Parameters:
schema- the schema of the messages to be senttopic- the topic the producer will send messages to ornullto 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:PulsarProducerFactoryCreate a producer.- Specified by:
createProducerin interfacePulsarProducerFactory<T>- Parameters:
schema- the schema of the messages to be senttopic- the topic the producer will send messages to ornullto use the default topiccustomizer- 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:PulsarProducerFactoryCreate a producer.- Specified by:
createProducerin interfacePulsarProducerFactory<T>- Parameters:
schema- the schema of the messages to be senttopic- the topic the producer will send messages to ornullto use the default topicencryptionKeys- the encryption keys used by the producer, replacing the default encryption keys ornullto use the default encryption keys. Beware thatProducerBuilderonly hasProducerBuilder.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:PulsarProducerFactoryGet the Pulsar client that the producer factory uses to create producers.- Specified by:
getPulsarClientin interfacePulsarProducerFactory<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 senttopic- the topic the producer will send messages to ornullto use the default topicencryptionKeys- the encryption keys used by the producer, replacing the default encryption keys ornullto use the default encryption keys. Beware thatProducerBuilderonly hasProducerBuilder.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
-
getDefaultTopic
Description copied from interface:PulsarProducerFactoryGet the default topic to use for all created producers.- Specified by:
getDefaultTopicin interfacePulsarProducerFactory<T>- Returns:
- the default topic to use for all created producers or null if no default set
-