Package org.apache.pulsar.client.api.v5
Interface Producer<T>
- Type Parameters:
T- the type of message values this producer sends
- All Superinterfaces:
AutoCloseable
A producer publishes messages to a Pulsar topic.
This interface provides synchronous (blocking) operations. For non-blocking
usage, obtain an AsyncProducer via async().
-
Method Summary
Modifier and TypeMethodDescriptionasync()Return the asynchronous view of this producer.voidclose()Close this producer and release all associated resources.longThe last sequence ID published by this producer.Create a message builder for advanced message construction (key, properties, etc.).The name of this producer (system-assigned or user-specified viaProducerBuilder.producerName(String)).topic()The topic this producer is attached to.
-
Method Details
-
topic
String topic()The topic this producer is attached to.- Returns:
- the fully qualified topic name (e.g.
topic://tenant/namespace/my-topic)
-
producerName
String producerName()The name of this producer (system-assigned or user-specified viaProducerBuilder.producerName(String)).- Returns:
- the producer name, never
null
-
newMessage
MessageBuilder<T> newMessage()Create a message builder for advanced message construction (key, properties, etc.). UseMessageBuilder.send()as the terminal operation.- Returns:
- a new
MessageBuilderinstance bound to this producer
-
lastSequenceId
long lastSequenceId()The last sequence ID published by this producer. Used for deduplication tracking. Returns-1if no message has been published yet.- Returns:
- the last published sequence ID, or
-1if none
-
async
AsyncProducer<T> async()Return the asynchronous view of this producer. The returned object shares the same underlying connection and resources.- Returns:
- the
AsyncProducercounterpart of this producer
-
close
Close this producer and release all associated resources. Pending send operations are completed before the producer is closed.- Specified by:
closein interfaceAutoCloseable- Throws:
PulsarClientException- if an error occurs while closing
-