Interface Producer<T>

Type Parameters:
T - the type of message values this producer sends
All Superinterfaces:
AutoCloseable

public interface Producer<T> extends 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 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 via ProducerBuilder.producerName(String)).
      Returns:
      the producer name, never null
    • newMessage

      MessageBuilder<T> newMessage()
      Create a message builder for advanced message construction (key, properties, etc.). Use MessageBuilder.send() as the terminal operation.
      Returns:
      a new MessageBuilder instance bound to this producer
    • lastSequenceId

      long lastSequenceId()
      The last sequence ID published by this producer. Used for deduplication tracking. Returns -1 if no message has been published yet.
      Returns:
      the last published sequence ID, or -1 if none
    • async

      AsyncProducer<T> async()
      Return the asynchronous view of this producer. The returned object shares the same underlying connection and resources.
      Returns:
      the AsyncProducer counterpart of this producer
    • close

      void close() throws PulsarClientException
      Close this producer and release all associated resources. Pending send operations are completed before the producer is closed.
      Specified by:
      close in interface AutoCloseable
      Throws:
      PulsarClientException - if an error occurs while closing