pulsar-client-cpp
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
pulsar::Producer Class Reference

Public Member Functions

 Producer ()
 
const std::string & getTopic () const
 
const std::string & getProducerName () const
 
Result send (const Message &msg)
 
Result send (const Message &msg, MessageId &messageId)
 
void sendAsync (const Message &msg, SendCallback callback)
 
Result flush ()
 
void flushAsync (FlushCallback callback)
 
int64_t getLastSequenceId () const
 
const std::string & getSchemaVersion () const
 
Result close ()
 
void closeAsync (CloseCallback callback)
 
bool isConnected () const
 

Friends

class ClientImpl
 
class PulsarFriend
 
class PulsarWrapper
 
class ProducerImpl
 

Constructor & Destructor Documentation

◆ Producer()

pulsar::Producer::Producer ( )

Construct an uninitialized Producer.

Member Function Documentation

◆ close()

Result pulsar::Producer::close ( )

Close the producer and release resources allocated.

No more writes will be accepted from this producer. Waits until all pending write requests are persisted. In case of errors, pending writes will not be retried.

Returns
an error code to indicate the success or failure

◆ closeAsync()

void pulsar::Producer::closeAsync ( CloseCallback  callback)

Close the producer and release resources allocated.

No more writes will be accepted from this producer. The provided callback will be triggered when all pending write requests are persisted. In case of errors, pending writes will not be retried.

◆ flush()

Result pulsar::Producer::flush ( )

Flush all the messages buffered in the client and wait until all messages have been successfully persisted.

◆ flushAsync()

void pulsar::Producer::flushAsync ( FlushCallback  callback)

Flush all the messages buffered in the client and wait until all messages have been successfully persisted.

◆ getLastSequenceId()

int64_t pulsar::Producer::getLastSequenceId ( ) const

Get the last sequence id that was published by this producer.

This represent either the automatically assigned or custom sequence id (set on the MessageBuilder) that was published and acknowledged by the broker.

After recreating a producer with the same producer name, this will return the last message that was published in the previous producer session, or -1 if there no message was ever published.

Returns
the last sequence id published by this producer

◆ getProducerName()

const std::string & pulsar::Producer::getProducerName ( ) const
Returns
the producer name which could have been assigned by the system or specified by the client

◆ getSchemaVersion()

const std::string & pulsar::Producer::getSchemaVersion ( ) const

Return an identifier for the schema version that this producer was created with.

When the producer is created, if a schema info was passed, the broker will determine the version of the passed schema. This identifier should be treated as an opaque identifier. In particular, even though this is represented as a string, the version might not be ascii printable.

◆ getTopic()

const std::string & pulsar::Producer::getTopic ( ) const
Returns
the topic to which producer is publishing to

◆ isConnected()

bool pulsar::Producer::isConnected ( ) const
Returns
Whether the producer is currently connected to the broker

◆ send() [1/2]

Result pulsar::Producer::send ( const Message msg)
Deprecated:
It's the same with send(const Message& msg, MessageId& messageId) except that MessageId will be stored in msg though msg is const.

◆ send() [2/2]

Result pulsar::Producer::send ( const Message msg,
MessageId messageId 
)

Publish a message on the topic associated with this Producer and get the associated MessageId.

This method will block until the message will be accepted and persisted by the broker. In case of errors, the client library will try to automatically recover and use a different broker.

If it wasn't possible to successfully publish the message within the sendTimeout, an error will be returned.

This method is equivalent to asyncSend() and wait until the callback is triggered.

Parameters
[in]msgmessage to publish
[out]messageIdthe message id assigned to the published message
Returns
ResultOk if the message was published successfully
ResultTimeout if message was not sent successfully in ProducerConfiguration::getSendTimeout
ResultProducerQueueIsFull if the outgoing messsage queue is full when ProducerConfiguration::getBlockIfQueueFull was false
ResultMessageTooBig if message size is bigger than the maximum message size
ResultAlreadyClosed if Producer was already closed when message was sent
ResultCryptoError if ProducerConfiguration::isEncryptionEnabled returns true but the message was failed to encrypt
ResultInvalidMessage if message's invalid, it's usually caused by resending the same Message

◆ sendAsync()

void pulsar::Producer::sendAsync ( const Message msg,
SendCallback  callback 
)

Asynchronously publish a message on the topic associated with this Producer.

This method will initiate the publish operation and return immediately. The provided callback will be triggered when the message has been be accepted and persisted by the broker. In case of errors, the client library will try to automatically recover and use a different broker.

If it wasn't possible to successfully publish the message within the sendTimeout, the callback will be triggered with a Result::WriteError code.

Parameters
msgmessage to publish
callbackthe callback to get notification of the completion

The documentation for this class was generated from the following file: