Interface PublisherInterface

All Known Implementing Classes:
Publisher

public interface PublisherInterface
An interface for a Cloud Pub/Sub publisher.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.google.api.core.ApiFuture<String>
    Schedules the publishing of a message.
  • Method Details

    • publish

      com.google.api.core.ApiFuture<String> publish(PubsubMessage message)
      Schedules the publishing of a message. The future will be returned with the message ID on success or an exception on failure.

      Some implementations of this method may block in the downcall until allowed by flow control.

      Example of publishing a message.

      
       String message = "my_message";
       ByteString data = ByteString.copyFromUtf8(message);
       PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();
       ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage);
       ApiFutures.addCallback(messageIdFuture, new ApiFutureCallback<String>() {
         public void onSuccess(String messageId) {
           System.out.println("published with message id: " + messageId);
         }
      
         public void onFailure(Throwable t) {
           System.out.println("failed to publish: " + t);
         }
       }, MoreExecutors.directExecutor());
       
      Parameters:
      message - the message to publish.
      Returns:
      the message ID wrapped in a future.