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

#include <ProducerInterceptor.h>

Public Member Functions

virtual void close ()
 
virtual Message beforeSend (const Producer &producer, const Message &message)=0
 
virtual void onSendAcknowledgement (const Producer &producer, Result result, const Message &message, const MessageId &messageID)=0
 
virtual void onPartitionsChange (const std::string &topicName, int partitions)
 

Detailed Description

An interface that allows you to intercept (and possibly mutate) the messages received by the producer before they are published to the Pulsar brokers.

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

ProducerInterceptor callbacks may be called from multiple threads. Interceptor implementation must ensure thread-safety, if needed.

Member Function Documentation

◆ beforeSend()

virtual Message pulsar::ProducerInterceptor::beforeSend ( const Producer producer,
const Message message 
)
pure virtual

This is called from Producer::send and Producer::sendAsync methods, before send the message to the brokers. This method is allowed to modify the record, in which case, the new record will be returned.

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

Since the producer may run multiple interceptors, a particular interceptor's #beforeSend(Producer, Message) callback will be called in the order specified by ProducerConfiguration::intercept().

The first interceptor in the list gets the message passed from the client, the following interceptor will be passed the message returned by the previous interceptor, and so on. Since interceptors are allowed to modify messages, interceptors may potentially get the message 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 the interceptors in the list throws an exception from beforeSend(Message), 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 client.

Parameters
producerthe producer which contains the interceptor.
messagemessage to send.
Returns
the intercepted message.

◆ close()

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

Close the interceptor

◆ onPartitionsChange()

virtual void pulsar::ProducerInterceptor::onPartitionsChange ( const std::string &  topicName,
int  partitions 
)
inlinevirtual

This method is called when partitions of the topic (partitioned-topic) changes.

Parameters
topicNametopic name
partitionsnew updated partitions

◆ onSendAcknowledgement()

virtual void pulsar::ProducerInterceptor::onSendAcknowledgement ( const Producer producer,
Result  result,
const Message message,
const MessageId messageID 
)
pure virtual

This method is called when the message sent to the broker has been acknowledged, or when sending the message fails. This method is generally called just before the user callback is called.

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

This method will generally execute in the background I/O thread, so the implementation should be reasonably fast. Otherwise, sending of messages from other threads could be delayed.

Parameters
producerthe producer which contains the interceptor.
resultthe result for sending messages, ResultOk indicates send has succeed.
messagethe message that application sends.
messageIDthe message id that assigned by the broker.

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