pulsar-client-cpp
Public Member Functions | List of all members
pulsar::ConsumerInterceptor Class Referenceabstract

#include <ConsumerInterceptor.h>

Public Member Functions

virtual void close ()
 
virtual Message beforeConsume (const Consumer &consumer, const Message &message)=0
 
virtual void onAcknowledge (const Consumer &consumer, Result result, const MessageId &messageID)=0
 
virtual void onAcknowledgeCumulative (const Consumer &consumer, Result result, const MessageId &messageID)=0
 
virtual void onNegativeAcksSend (const Consumer &consumer, const std::set< MessageId > &messageIds)=0
 

Detailed Description

A plugin interface that allows you to intercept (and possibly mutate) messages received by the consumer.

A primary use case is to hook into consumer applications for custom monitoring, logging, etc.

Exceptions thrown by interceptor methods will be caught, logged, but not propagated further.

Member Function Documentation

◆ beforeConsume()

virtual Message pulsar::ConsumerInterceptor::beforeConsume ( const Consumer consumer,
const Message message 
)
pure virtual

This is called just before the message is consumed.

This method is allowed to modify message, in which case the new message will be returned.

Any exception thrown by this method will be caught by the caller, logged, but not propagated to client.

Since the consumer may run multiple interceptors, a particular interceptor's beforeConsume callback will be called in the order. The first interceptor in the list gets the consumed message, the following interceptor will be passed the message returned by the previous interceptor, and so on. Since interceptors are allowed to modify message, interceptors may potentially get the messages already modified by other interceptors. However building a pipeline of mutable interceptors that depend on the output of the previous interceptor is discouraged, because of potential side-effects caused by interceptors potentially failing to modify the message and throwing an exception. if one of interceptors in the list throws an exception from beforeConsume, the exception is caught, logged, and the next interceptor is called with the message returned by the last successful interceptor in the list, or otherwise the original consumed message.

Parameters
consumerthe consumer which contains the interceptor
messagethe message to be consumed by the client
Returns
message that is either modified by the interceptor or same message passed into the method.

◆ close()

virtual void pulsar::ConsumerInterceptor::close ( )
inlinevirtual

Close the interceptor

◆ onAcknowledge()

virtual void pulsar::ConsumerInterceptor::onAcknowledge ( const Consumer consumer,
Result  result,
const MessageId messageID 
)
pure virtual

This is called before consumer sends the acknowledgment to the broker.

Any exception thrown by this method will be ignored by the caller.

Parameters
consumerthe consumer which contains the interceptor
resultthe result of the acknowledgement
messageIDthe message id to be acknowledged

◆ onAcknowledgeCumulative()

virtual void pulsar::ConsumerInterceptor::onAcknowledgeCumulative ( const Consumer consumer,
Result  result,
const MessageId messageID 
)
pure virtual

This is called before consumer sends the cumulative acknowledgment to the broker.

Any exception thrown by this method will be ignored by the caller.

Parameters
consumerthe consumer which contains the interceptor
resultthe result of the cumulative acknowledgement
messageIDthe message id to be acknowledged cumulatively

◆ onNegativeAcksSend()

virtual void pulsar::ConsumerInterceptor::onNegativeAcksSend ( const Consumer consumer,
const std::set< MessageId > &  messageIds 
)
pure virtual

This method will be called when a redelivery from a negative acknowledge occurs.

Any exception thrown by this method will be ignored by the caller.

Parameters
consumerthe consumer which contains the interceptor
messageIdsthe set of message ids to negative ack

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