public interface PubSub extends AutoCloseable, Service<PubSubOptions>
| Modifier and Type | Interface and Description |
|---|---|
static class |
PubSub.ListOption
Class for specifying options for listing topics and subscriptions.
|
static interface |
PubSub.MessageConsumer
An interface to control a message consumer.
|
static interface |
PubSub.MessageProcessor
A callback to process pulled messages.
|
static class |
PubSub.PullOption
Class for specifying options for pulling messages.
|
| Modifier and Type | Method and Description |
|---|---|
void |
ack(String subscription,
Iterable<String> ackIds)
Acknowledges the given messages for the provided subscription.
|
void |
ack(String subscription,
String ackId,
String... ackIds)
Acknowledges the given messages for the provided subscription.
|
Future<Void> |
ackAsync(String subscription,
Iterable<String> ackIds)
Sends a request to acknowledge the given messages for the provided subscription.
|
Future<Void> |
ackAsync(String subscription,
String ackId,
String... ackIds)
Sends a request to acknowledge the given messages for the provided subscription.
|
Subscription |
create(SubscriptionInfo subscription)
Creates a new subscription.
|
Topic |
create(TopicInfo topic)
Creates a new topic.
|
Future<Subscription> |
createAsync(SubscriptionInfo subscription)
Sends a request for creating a subscription.
|
Future<Topic> |
createAsync(TopicInfo topic)
Sends a request for creating a topic.
|
boolean |
deleteSubscription(String subscription)
Deletes the requested subscription.
|
Future<Boolean> |
deleteSubscriptionAsync(String subscription)
Sends a request for deleting a subscription.
|
boolean |
deleteTopic(String topic)
Deletes the requested topic.
|
Future<Boolean> |
deleteTopicAsync(String topic)
Sends a request for deleting a topic.
|
Subscription |
getSubscription(String subscription)
Returns the requested subscription or
null if not found. |
Future<Subscription> |
getSubscriptionAsync(String subscription)
Sends a request for getting a subscription.
|
Topic |
getTopic(String topic)
Returns the requested topic or
null if not found. |
Future<Topic> |
getTopicAsync(String topic)
Sends a request for getting a topic.
|
Page<Subscription> |
listSubscriptions(PubSub.ListOption... options)
Lists the subscriptions.
|
Page<SubscriptionId> |
listSubscriptions(String topic,
PubSub.ListOption... options)
Lists the identities of the subscriptions for the provided topic.
|
Future<AsyncPage<Subscription>> |
listSubscriptionsAsync(PubSub.ListOption... options)
Sends a request for listing subscriptions.
|
Future<AsyncPage<SubscriptionId>> |
listSubscriptionsAsync(String topic,
PubSub.ListOption... options)
Sends a request for listing the identities of subscriptions for the provided topic.
|
Page<Topic> |
listTopics(PubSub.ListOption... options)
Lists the topics.
|
Future<AsyncPage<Topic>> |
listTopicsAsync(PubSub.ListOption... options)
Sends a request for listing topics.
|
void |
modifyAckDeadline(String subscription,
int deadline,
TimeUnit unit,
Iterable<String> ackIds)
Modifies the acknowledge deadline of the given messages.
|
void |
modifyAckDeadline(String subscription,
int deadline,
TimeUnit unit,
String ackId,
String... ackIds)
Modifies the acknowledge deadline of the given messages.
|
Future<Void> |
modifyAckDeadlineAsync(String subscription,
int deadline,
TimeUnit unit,
Iterable<String> ackIds)
Sends a request to modify the acknowledge deadline of the given messages.
|
Future<Void> |
modifyAckDeadlineAsync(String subscription,
int deadline,
TimeUnit unit,
String ackId,
String... ackIds)
Sends a request to modify the acknowledge deadline of the given messages.
|
void |
nack(String subscription,
Iterable<String> ackIds)
"Nacks" the given messages for the provided subscription.
|
void |
nack(String subscription,
String ackId,
String... ackIds)
"Nacks" the given messages for the provided subscription.
|
Future<Void> |
nackAsync(String subscription,
Iterable<String> ackIds)
Sends a request to "nack" the given messages for the provided subscription.
|
Future<Void> |
nackAsync(String subscription,
String ackId,
String... ackIds)
Sends a request to "nack" the given messages for the provided subscription.
|
List<String> |
publish(String topic,
Iterable<Message> messages)
Publishes a number of messages to the provided topic.
|
String |
publish(String topic,
Message message)
Publishes a message to the provided topic.
|
List<String> |
publish(String topic,
Message message,
Message... messages)
Publishes a number of messages to the provided topic.
|
Future<List<String>> |
publishAsync(String topic,
Iterable<Message> messages)
Sends a request to publish a number of messages to the provided topic.
|
Future<String> |
publishAsync(String topic,
Message message)
Sends a request for publishing a message to the provided topic.
|
Future<List<String>> |
publishAsync(String topic,
Message message,
Message... messages)
Sends a request to publish a number of messages to the provided topic.
|
Iterator<ReceivedMessage> |
pull(String subscription,
int maxMessages)
Pulls messages from the provided subscription.
|
Future<Iterator<ReceivedMessage>> |
pullAsync(String subscription,
int maxMessages)
Sends a request for pulling messages from the provided subscription.
|
PubSub.MessageConsumer |
pullAsync(String subscription,
PubSub.MessageProcessor callback,
PubSub.PullOption... options)
Creates a message consumer that pulls messages from the provided subscription.
|
void |
replacePushConfig(String subscription,
PushConfig pushConfig)
Sets the push configuration for a specified subscription.
|
Future<Void> |
replacePushConfigAsync(String subscription,
PushConfig pushConfig)
Sends a request for updating the push configuration for a specified subscription.
|
closeTopic create(TopicInfo topic)
PubSubException - upon failureFuture<Topic> createAsync(TopicInfo topic)
Future object to consume
the result. Future.get() returns the created topic.Topic getTopic(String topic)
null if not found.PubSubException - upon failureFuture<Topic> getTopicAsync(String topic)
Future object to consume the
result. Future.get() returns the requested topic or null if not found.PubSubException - upon failureboolean deleteTopic(String topic)
true if the topic was deleted, false if it was not foundFuture<Boolean> deleteTopicAsync(String topic)
Future object to consume
the result. Future.get() returns true if the topic was deleted, false
if it was not found.Page<Topic> listTopics(PubSub.ListOption... options)
Page object that can be used to consume
paginated results. Use PubSub.ListOption to specify the page size or the page token from which
to start listing topics.PubSubException - upon failureFuture<AsyncPage<Topic>> listTopicsAsync(PubSub.ListOption... options)
Future object to consume
the result. Future.get() returns an AsyncPage object that can be used to
asynchronously handle paginated results. Use PubSub.ListOption to specify the page size or the
page token from which to start listing topics.String publish(String topic, Message message)
topic - the topic where the message is publishedmessage - the message to publishPubSubException - upon failure, if the topic does not exist or if the message has empty
payload and no attributesFuture<String> publishAsync(String topic, Message message)
Future object to consume the result. Future.get() returns a service-generated
id for the published message. Service-generated ids are guaranteed to be unique within the
topic.topic - the topic where the message is publishedmessage - the message to publishFuture for the unique service-generated id for the messageList<String> publish(String topic, Message message, Message... messages)
topic - the topic where the message is publishedmessage - the first message to publishmessages - other messages to publishPubSubException - upon failure, if the topic does not exist or if one of the messages has
empty payload and no attributesFuture<List<String>> publishAsync(String topic, Message message, Message... messages)
Future object to consume the result. Future.get() returns a list of
service-generated ids for the published messages. Service-generated ids are guaranteed to be
unique within the topic.topic - the topic where the message is publishedmessage - the first message to publishmessages - other messages to publishFuture for the unique, service-generated ids. Ids are in the same order as
the messages.List<String> publish(String topic, Iterable<Message> messages)
topic - the topic where the message is publishedmessages - the messages to publishPubSubException - upon failure, if the topic does not exist or if one of the messages has
empty payload and no attributesFuture<List<String>> publishAsync(String topic, Iterable<Message> messages)
Future object to consume the result. Future.get() returns a list of
service-generated ids for the published messages. Service-generated ids are guaranteed to be
unique within the topic.topic - the topic where the message is publishedmessages - the messages to publishFuture for the unique, service-generated ids. Ids are in the same order as
the messagesSubscription create(SubscriptionInfo subscription)
PubSubException - upon failureFuture<Subscription> createAsync(SubscriptionInfo subscription)
Future object to
consume the result. Future.get() returns the created subscription.Subscription getSubscription(String subscription)
null if not found.Future<Subscription> getSubscriptionAsync(String subscription)
Future object to
consume the result. Future.get() returns the requested subscription or null if
not found.void replacePushConfig(String subscription, PushConfig pushConfig)
null pushConfig parameter) or vice versa.
This methods can also be used to change the endpoint URL and other attributes of a push
subscription. Messages will accumulate for delivery regardless of changes to the push
configuration.subscription - the subscription for which to replace push configurationpushConfig - the new push configuration. Use null to unset itPubSubException - upon failure, or if the subscription does not existFuture<Void> replacePushConfigAsync(String subscription, PushConfig pushConfig)
null pushConfig
parameter) or vice versa. This methods can also be used to change the endpoint URL and other
attributes of a push subscription. Messages will accumulate for delivery regardless of changes
to the push configuration. The method returns a Future object that can be used to wait
for the replace operation to be completed.subscription - the subscription for which to replace push configurationpushConfig - the new push configuration. Use null to unset itFuture to wait for the replace operation to be completed.boolean deleteSubscription(String subscription)
true if the subscription was deleted, false if it was not foundPubSubException - upon failureFuture<Boolean> deleteSubscriptionAsync(String subscription)
Future object to
consume the result. Future.get() returns true if the subscription was deleted,
false if it was not found.Page<Subscription> listSubscriptions(PubSub.ListOption... options)
Page object that can be used to consume
paginated results. Use PubSub.ListOption to specify the page size or the page token from which
to start listing subscriptions.PubSubException - upon failureFuture<AsyncPage<Subscription>> listSubscriptionsAsync(PubSub.ListOption... options)
Future object to
consume the result. Future.get() returns an AsyncPage object that can be used
to asynchronously handle paginated results. Use PubSub.ListOption to specify the page size or
the page token from which to start listing subscriptions.PubSubException - upon failurePage<SubscriptionId> listSubscriptions(String topic, PubSub.ListOption... options)
Page object that can be used to consume paginated results. Use PubSub.ListOption to
specify the page size or the page token from which to start listing subscriptions.topic - the topic for which to list subscriptionsPubSubException - upon failureFuture<AsyncPage<SubscriptionId>> listSubscriptionsAsync(String topic, PubSub.ListOption... options)
Future object to consume the result. Future.get() returns an
AsyncPage object that can be used to asynchronously handle paginated results. Use
PubSub.ListOption to specify the page size or the page token from which to start listing
subscriptions.topic - the topic for which to list subscriptionsIterator<ReceivedMessage> pull(String subscription, int maxMessages)
Iterator.next().
Example usage of synchronous message pulling:
Iterator<ReceivedMessage> messageIterator = pubsub.pull("subscription", 100);
while (messageIterator.hasNext()) {
ReceivedMessage message = messageIterator.next();
// message's acknowledge deadline is no longer automatically renewed. If processing takes
// long pubsub.modifyAckDeadline(String, String, long, TimeUnit) can be used to extend it.
doSomething(message);
message.ack(); // or message.nack()
}subscription - the subscription from which to pull messagesmaxMessages - the maximum number of messages pulled by this method. This method can
possibly return fewer messages.PubSubException - upon failureFuture<Iterator<ReceivedMessage>> pullAsync(String subscription, int maxMessages)
Future object to consume the result. Future.get() returns a message iterator.
This method possibly returns no messages if no message was available at the time the request
was processed by the Pub/Sub service (i.e. the system is not allowed to wait until at least one
message is available).
Example usage of asynchronous message pulling:
Future<Iterator<ReceivedMessage>> future = pubsub.pull("subscription", 100);
// do something while the request gets processed
Iterator<ReceivedMessage> messageIterator = future.get();
while (messageIterator.hasNext()) {
ReceivedMessage message = messageIterator.next();
// message's acknowledge deadline is no longer automatically renewed. If processing takes
// long pubsub.modifyAckDeadline(String, String, long, TimeUnit) can be used to extend it.
doSomething(message);
message.ack(); // or message.nack()
}subscription - the subscription from which to pull messagesmaxMessages - the maximum number of messages pulled by this method. This method can
possibly return fewer messages.PubSubException - upon failurePubSub.MessageConsumer pullAsync(String subscription, PubSub.MessageProcessor callback, PubSub.PullOption... options)
PubSub.MessageConsumer.close(). The returned message consumer
executes PubSub.MessageProcessor.process(Message) on each pulled message. If
PubSub.MessageProcessor.process(Message) executes correctly, the message is acknowledged. If
PubSub.MessageProcessor.process(Message) throws an exception, the message is "nacked". For
all pulled messages, the ack deadline is automatically renewed until the message is either
acknowledged or "nacked".
The PubSub.PullOption.maxQueuedCallbacks(int) option can be used to control the maximum
number of queued messages (messages either being processed or waiting to be processed). The
PullOption#executorFactory(ExecutorFactory) can be used to provide an executor to run
message processor callbacks.
subscription - the subscription from which to pull messagescallback - the callback to be executed on each messageoptions - pulling optionsvoid ack(String subscription, String ackId, String... ackIds)
ReceivedMessage.ackId() by pull(String, int) and
pullAsync(String, int).subscription - the subscription whose messages must be acknowledgedackId - the ack id of the first message to acknowledgeackIds - other ack ids of messages to acknowledgePubSubException - upon failure, or if the subscription was not foundFuture<Void> ackAsync(String subscription, String ackId, String... ackIds)
ReceivedMessage.ackId() by
pull(String, int) and pullAsync(String, int). The method returns a
Future object that can be used to wait for the acknowledge operation to be completed.subscription - the subscription whose messages must be acknowledgedackId - the ack id of the first message to acknowledgeackIds - other ack ids of messages to acknowledgevoid ack(String subscription, Iterable<String> ackIds)
ReceivedMessage.ackId() by pull(String, int) and
pullAsync(String, int).subscription - the subscription whose messages must be acknowledgedackIds - the ack ids of messages to acknowledgePubSubException - upon failure, or if the subscription was not foundFuture<Void> ackAsync(String subscription, Iterable<String> ackIds)
ReceivedMessage.ackId() by
pull(String, int) and pullAsync(String, int). The method returns a
Future object that can be used to wait for the acknowledge operation to be completed.subscription - the subscription whose messages must be acknowledgedackIds - the ack ids of messages to acknowledgevoid nack(String subscription, String ackId, String... ackIds)
ReceivedMessage.ackId() by pull(String, int) and
pullAsync(String, int). This method corresponds to calling
modifyAckDeadline(String, int, TimeUnit, String, String...) with a deadline of 0.subscription - the subscription whose messages must be "nacked"ackId - the ack id of the first message to "nack"ackIds - other ack ids of messages to "nack"PubSubException - upon failure, or if the subscription was not foundFuture<Void> nackAsync(String subscription, String ackId, String... ackIds)
ReceivedMessage.ackId() by
pull(String, int) and pullAsync(String, int). This method corresponds to
calling modifyAckDeadlineAsync(String, int, TimeUnit, String, String...) with a
deadline of 0. The method returns a Future object that can be used to wait for the
"nack" operation to be completed.subscription - the subscription whose messages must be "nacked"ackId - the ack id of the first message to "nack"ackIds - other ack ids of messages to "nack"void nack(String subscription, Iterable<String> ackIds)
ReceivedMessage.ackId() by pull(String, int) and
pullAsync(String, int). This method corresponds to calling
modifyAckDeadline(String, int, TimeUnit, Iterable) with a deadline of 0.subscription - the subscription whose messages must be "nacked"ackIds - the ack ids of messages to "nack"PubSubException - upon failure, or if the subscription was not foundFuture<Void> nackAsync(String subscription, Iterable<String> ackIds)
ReceivedMessage.ackId() by
pull(String, int) and pullAsync(String, int). This method corresponds to
calling modifyAckDeadlineAsync(String, int, TimeUnit, Iterable) with a deadline of 0.
The method returns a Future object that can be used to wait for the "nack" operation to
be completed.subscription - the subscription whose messages must be "nacked"ackIds - the ack ids of messages to "nack"void modifyAckDeadline(String subscription, int deadline, TimeUnit unit, String ackId, String... ackIds)
deadline must be >= 0 and
is the new deadline with respect to the time the modify request was received by the Pub/Sub
service. For example, if deadline is 10 and unit is TimeUnit.SECONDS,
the new ack deadline will expire 10 seconds after the modify request was received by the
service. Specifying 0 may be used to make the message available for another pull request
(corresponds to calling nack(String, String, String...)).subscription - the subscription whose messages need to update their acknowledge deadlinedeadline - the new deadline, relative to the time the modify request is received by the
Pub/Sub serviceunit - time unit for the deadline parameterackId - the ack id of the first message for which the acknowledge deadline must be
modifiedackIds - other ack ids of messages for which the acknowledge deadline must be modifiedPubSubException - upon failure, or if the subscription was not foundFuture<Void> modifyAckDeadlineAsync(String subscription, int deadline, TimeUnit unit, String ackId, String... ackIds)
deadline
must be >= 0 and is the new deadline with respect to the time the modify request was
received by the Pub/Sub service. For example, if deadline is 10 and unit is
TimeUnit.SECONDS, the new ack deadline will expire 10 seconds after the modify request
was received by the service. Specifying 0 may be used to make the message available for another
pull request (corresponds to calling nackAsync(String, Iterable)). The method returns
a Future object that can be used to wait for the modify operation to be completed.subscription - the subscription whose messages need to update their acknowledge deadlinedeadline - the new deadline, relative to the time the modify request is received by the
Pub/Sub serviceunit - time unit for the deadline parameterackId - the ack id of the first message for which the acknowledge deadline must be
modifiedackIds - other ack ids of messages for which the acknowledge deadline must be modifiedvoid modifyAckDeadline(String subscription, int deadline, TimeUnit unit, Iterable<String> ackIds)
deadline must be >= 0 and
is the new deadline with respect to the time the modify request was received by the Pub/Sub
service. For example, if deadline is 10 and unit is TimeUnit.SECONDS,
the new ack deadline will expire 10 seconds after the modify request was received by the
service. Specifying 0 may be used to make the message available for another pull request
(corresponds to calling nack(String, Iterable)).subscription - the subscription whose messages need to update their acknowledge deadlinedeadline - the new deadline, relative to the time the modify request is received by the
Pub/Sub serviceunit - time unit for the deadline parameterackIds - the ack ids of messages for which the acknowledge deadline must be modifiedPubSubException - upon failure, or if the subscription was not foundFuture<Void> modifyAckDeadlineAsync(String subscription, int deadline, TimeUnit unit, Iterable<String> ackIds)
deadline
must be >= 0 and is the new deadline with respect to the time the modify request was
received by the Pub/Sub service. For example, if deadline is 10 and unit is
TimeUnit.SECONDS, the new ack deadline will expire 10 seconds after the modify request
was received by the service. Specifying 0 may be used to make the message available for another
pull request (corresponds to calling nackAsync(String, Iterable)). The method returns
a Future object that can be used to wait for the modify operation to be completed.subscription - the subscription whose messages need to update their acknowledge deadlinedeadline - the new deadline, relative to the time the modify request is received by the
Pub/Sub serviceunit - time unit for the deadline parameterackIds - the ack ids of messages for which the acknowledge deadline must be modifiedCopyright © 2016 Google. All rights reserved.