pulsar-client-cpp
Public Member Functions | Friends | List of all members
pulsar::Consumer Class Reference

Public Member Functions

 Consumer ()
 
const std::string & getTopic () const
 
const std::string & getSubscriptionName () const
 
Result unsubscribe ()
 
void unsubscribeAsync (ResultCallback callback)
 
Result receive (Message &msg)
 
Result receive (Message &msg, int timeoutMs)
 
Result acknowledge (const Message &message)
 
Result acknowledge (const MessageId &messageId)
 
void acknowledgeAsync (const Message &message, ResultCallback callback)
 
void acknowledgeAsync (const MessageId &messageID, ResultCallback callback)
 
Result acknowledgeCumulative (const Message &message)
 
Result acknowledgeCumulative (const MessageId &messageId)
 
void acknowledgeCumulativeAsync (const Message &message, ResultCallback callback)
 
void acknowledgeCumulativeAsync (const MessageId &messageId, ResultCallback callback)
 
Result close ()
 
void closeAsync (ResultCallback callback)
 
Result pauseMessageListener ()
 
Result resumeMessageListener ()
 
void redeliverUnacknowledgedMessages ()
 
Result getBrokerConsumerStats (BrokerConsumerStats &brokerConsumerStats)
 
void getBrokerConsumerStatsAsync (BrokerConsumerStatsCallback callback)
 

Friends

class PulsarFriend
 
class PulsarWrapper
 
class PartitionedConsumerImpl
 
class ConsumerImpl
 
class ClientImpl
 
class ConsumerTest
 

Constructor & Destructor Documentation

◆ Consumer()

pulsar::Consumer::Consumer ( )

Construct an uninitialized consumer object

Member Function Documentation

◆ acknowledge()

Result pulsar::Consumer::acknowledge ( const Message message)

Acknowledge the reception of a single message.

This method will block until an acknowledgement is sent to the broker. After that, the message will not be re-delivered to this consumer.

See also
asyncAcknowledge
Parameters
messagethe message to acknowledge
Returns
ResultOk if the message was successfully acknowledged
ResultError if there was a failure

◆ acknowledgeAsync()

void pulsar::Consumer::acknowledgeAsync ( const Message message,
ResultCallback  callback 
)

Asynchronously acknowledge the reception of a single message.

This method will initiate the operation and return immediately. The provided callback will be triggered when the operation is complete.

Parameters
messagethe message to acknowledge
callbackcallback that will be triggered when the message has been acknowledged

◆ acknowledgeCumulative()

Result pulsar::Consumer::acknowledgeCumulative ( const Message message)

Acknowledge the reception of all the messages in the stream up to (and including) the provided message.

This method will block until an acknowledgement is sent to the broker. After that, the messages will not be re-delivered to this consumer.

Cumulative acknowledge cannot be used when the consumer type is set to ConsumerShared.

It's equivalent to calling asyncAcknowledgeCumulative(const Message&, ResultCallback) and waiting for the callback to be triggered.

Parameters
messagethe last message in the stream to acknowledge
Returns
ResultOk if the message was successfully acknowledged. All previously delivered messages for this topic are also acknowledged.
ResultError if there was a failure

◆ acknowledgeCumulativeAsync()

void pulsar::Consumer::acknowledgeCumulativeAsync ( const Message message,
ResultCallback  callback 
)

Asynchronously acknowledge the reception of all the messages in the stream up to (and including) the provided message.

This method will initiate the operation and return immediately. The provided callback will be triggered when the operation is complete.

Parameters
messagethe message to acknowledge
callbackcallback that will be triggered when the message has been acknowledged

◆ getBrokerConsumerStats()

Result pulsar::Consumer::getBrokerConsumerStats ( BrokerConsumerStats brokerConsumerStats)

Gets Consumer Stats from broker. The stats are cached for 30 seconds, if a call is made before the stats returned by the previous call expires then cached data will be returned. BrokerConsumerStats::isValid() function can be used to check if the stats are still valid.

Parameters
brokerConsumerStats- if the function returns ResultOk, this object will contain consumer stats
Note
This is a blocking call with timeout of thirty seconds.

◆ getBrokerConsumerStatsAsync()

void pulsar::Consumer::getBrokerConsumerStatsAsync ( BrokerConsumerStatsCallback  callback)

Asynchronous call to gets Consumer Stats from broker. The stats are cached for 30 seconds, if a call is made before the stats returned by the previous call expires then cached data will be returned. BrokerConsumerStats::isValid() function can be used to check if the stats are still valid.

Parameters
callback- callback function to get the brokerConsumerStats, if result is ResultOk then the brokerConsumerStats will be populated

◆ getSubscriptionName()

const std::string& pulsar::Consumer::getSubscriptionName ( ) const
Returns
the consumer name

◆ getTopic()

const std::string& pulsar::Consumer::getTopic ( ) const
Returns
the topic this consumer is subscribed to

◆ receive() [1/2]

Result pulsar::Consumer::receive ( Message msg)

Receive a single message.

If a message is not immediately available, this method will block until a new message is available.

Parameters
msga non-const reference where the received message will be copied
Returns
ResultOk when a message is received
ResultInvalidConfiguration if a message listener had been set in the configuration

◆ receive() [2/2]

Result pulsar::Consumer::receive ( Message msg,
int  timeoutMs 
)
Parameters
msga non-const reference where the received message will be copied
timeoutMsthe receive timeout in milliseconds
Returns
ResultOk if a message was received
ResultTimeout if the receive timeout was triggered
ResultInvalidConfiguration if a message listener had been set in the configuration

◆ redeliverUnacknowledgedMessages()

void pulsar::Consumer::redeliverUnacknowledgedMessages ( )

Redelivers all the unacknowledged messages. In Failover mode, the request is ignored if the consumer is not active for the given topic. In Shared mode, the consumers messages to be redelivered are distributed across all the connected consumers. This is a non blocking call and doesn't throw an exception. In case the connection breaks, the messages are redelivered after reconnect.

◆ unsubscribe()

Result pulsar::Consumer::unsubscribe ( )

Unsubscribe the current consumer from the topic.

This method will block until the operation is completed. Once the consumer is unsubscribed, no more messages will be received and subsequent new messages will not be retained for this consumer.

This consumer object cannot be reused.

See also
asyncUnsubscribe
Returns
Result::ResultOk if the unsubscribe operation completed successfully
Result::ResultError if the unsubscribe operation failed

◆ unsubscribeAsync()

void pulsar::Consumer::unsubscribeAsync ( ResultCallback  callback)

Asynchronously unsubscribe the current consumer from the topic.

This method will block until the operation is completed. Once the consumer is unsubscribed, no more messages will be received and subsequent new messages will not be retained for this consumer.

This consumer object cannot be reused.

Parameters
callbackthe callback to get notified when the operation is complete

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