Package com.google.cloud.pubsub.v1
Interface PublisherInterface
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description com.google.api.core.ApiFuture<String>
publish(PubsubMessage message)
Schedules the publishing of a message.
-
-
-
Method Detail
-
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.
-
-