Modifier and Type | Method and Description |
---|---|
com.google.api.core.ApiFuture<String> |
publish(PubsubMessage message)
Schedules the publishing of a message.
|
com.google.api.core.ApiFuture<String> publish(PubsubMessage message)
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());
message
- the message to publish.Copyright © 2023 Google LLC. All rights reserved.