Interface MessageReceiver (1.135.0)

public interface MessageReceiver

This interface can be implemented by users of Subscriber to receive messages.

Methods

receiveMessage(PubsubMessage message, AckReplyConsumer consumer)

public abstract void receiveMessage(PubsubMessage message, AckReplyConsumer consumer)

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.
 MessageReceiver receiver =
     new MessageReceiver() {
       public void receiveMessage(final PubsubMessage message, final AckReplyConsumer consumer) {
         if (blockingQueue.offer(message)) {
           consumer.ack();
         } else {
           consumer.nack();
         }
       }
     };

 
Parameters
Name Description
message PubsubMessage
consumer AckReplyConsumer