Class OpenCensusUtil.OpenCensusMessageReceiver (1.143.0)

publicstaticclass OpenCensusUtil.OpenCensusMessageReceiverimplementsMessageReceiver

Wrapper class for MessageReceiver that decodes any received trace and tag contexts and puts them in scope.

Inheritance

java.lang.Object > OpenCensusUtil.OpenCensusMessageReceiver

Implements

MessageReceiver

Constructors

OpenCensusMessageReceiver(MessageReceiver receiver)

publicOpenCensusMessageReceiver(MessageReceiverreceiver)
Parameter
Name Description
receiver MessageReceiver

Methods

receiveMessage(PubsubMessage message, AckReplyConsumer consumer)

publicvoidreceiveMessage(PubsubMessagemessage,AckReplyConsumerconsumer)

Called when a message is received by the subscriber. The implementation must arrange for AckReplyConsumer#ack() or AckReplyConsumer#nack() to be called after processing the message.


// This {@code MessageReceiver} passes all messages to a BlockingQueue. This method can
// be called concurrently from multiple threads, so it is important that the queue be
// thread-safe.
//
// This example is for illustration. Implementations may directly process messages instead of
// sending them to queues.
MessageReceiverreceiver=
newMessageReceiver(){
publicvoidreceiveMessage(finalPubsubMessagemessage,finalAckReplyConsumerconsumer){
if(blockingQueue.offer(message)){
consumer.ack();
}else{
consumer.nack();
}
}
};
Parameters
Name Description
message PubsubMessage
consumer AckReplyConsumer

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.