public class PubSubSubscriberTemplate extends Object implements PubSubSubscriberOperations, org.springframework.beans.factory.DisposableBean
PubSubSubscriberOperations.
The main Google Cloud Pub/Sub integration component for consuming
messages from subscriptions asynchronously or by pulling.
A custom Executor can be injected to control per-subscription batch
parallelization in acknowledgement and deadline operations.
| Constructor and Description |
|---|
PubSubSubscriberTemplate(SubscriberFactory subscriberFactory)
Default
PubSubSubscriberTemplate constructor. |
| Modifier and Type | Method and Description |
|---|---|
org.springframework.util.concurrent.ListenableFuture<Void> |
ack(Collection<AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages)
Acknowledge messages in per-subscription batches.
|
void |
destroy()
Destroys the default executor, regardless of whether it was used.
|
PubSubMessageConverter |
getMessageConverter() |
SubscriberFactory |
getSubscriberFactory() |
org.springframework.util.concurrent.ListenableFuture<Void> |
modifyAckDeadline(Collection<AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages,
int ackDeadlineSeconds)
Modify multiple messages' ack deadline in per-subscription batches.
|
org.springframework.util.concurrent.ListenableFuture<Void> |
nack(Collection<AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages)
Nack messages in per-subscription batches.
|
List<AcknowledgeablePubsubMessage> |
pull(String subscription,
Integer maxMessages,
Boolean returnImmediately)
Pull a number of messages from a Google Cloud Pub/Sub subscription.
|
List<com.google.pubsub.v1.PubsubMessage> |
pullAndAck(String subscription,
Integer maxMessages,
Boolean returnImmediately)
Pull and auto-acknowledge a number of messages from a Google Cloud Pub/Sub subscription.
|
<T> List<ConvertedAcknowledgeablePubsubMessage<T>> |
pullAndConvert(String subscription,
Integer maxMessages,
Boolean returnImmediately,
Class<T> payloadType)
Pull a number of messages from a Google Cloud Pub/Sub subscription and convert them to Spring messages with
the desired payload type.
|
com.google.pubsub.v1.PubsubMessage |
pullNext(String subscription)
Pull and auto-acknowledge a message from a Google Cloud Pub/Sub subscription.
|
void |
setAckExecutor(Executor ackExecutor) |
void |
setMessageConverter(PubSubMessageConverter pubSubMessageConverter) |
com.google.cloud.pubsub.v1.Subscriber |
subscribe(String subscription,
Consumer<BasicAcknowledgeablePubsubMessage> messageConsumer)
Add a callback method to an existing subscription.
|
com.google.cloud.pubsub.v1.Subscriber |
subscribe(String subscription,
com.google.cloud.pubsub.v1.MessageReceiver messageReceiver)
Deprecated.
|
<T> com.google.cloud.pubsub.v1.Subscriber |
subscribeAndConvert(String subscription,
Consumer<ConvertedBasicAcknowledgeablePubsubMessage<T>> messageConsumer,
Class<T> payloadType)
Add a callback method to an existing subscription that receives Pub/Sub messages converted to the requested
payload type.
|
public PubSubSubscriberTemplate(SubscriberFactory subscriberFactory)
PubSubSubscriberTemplate constructor.subscriberFactory - the Subscriber factory
to subscribe to subscriptions or pull messages.public PubSubMessageConverter getMessageConverter()
public void setMessageConverter(PubSubMessageConverter pubSubMessageConverter)
public void setAckExecutor(Executor ackExecutor)
@Deprecated public com.google.cloud.pubsub.v1.Subscriber subscribe(String subscription, com.google.cloud.pubsub.v1.MessageReceiver messageReceiver)
PubSubSubscriberOperationssubscribe in interface PubSubSubscriberOperationssubscription - the subscription to subscribe tomessageReceiver - the message receiver with which to subscribepublic com.google.cloud.pubsub.v1.Subscriber subscribe(String subscription, Consumer<BasicAcknowledgeablePubsubMessage> messageConsumer)
PubSubSubscriberOperationsThe created Subscriber is returned so it can be stopped.
subscribe in interface PubSubSubscriberOperationssubscription - the name of an existing subscriptionmessageConsumer - the callback method triggered when new messages arrivepublic <T> com.google.cloud.pubsub.v1.Subscriber subscribeAndConvert(String subscription, Consumer<ConvertedBasicAcknowledgeablePubsubMessage<T>> messageConsumer, Class<T> payloadType)
PubSubSubscriberOperationsThe created Subscriber is returned so it can be stopped.
subscribeAndConvert in interface PubSubSubscriberOperationsT - the type of the payloadsubscription - the name of an existing subscriptionmessageConsumer - the callback method triggered when new messages arrivepayloadType - the type to which the payload of the Pub/Sub message should be convertedpublic List<AcknowledgeablePubsubMessage> pull(String subscription, Integer maxMessages, Boolean returnImmediately)
PubSubSubscriberOperationspull in interface PubSubSubscriberOperationssubscription - the subscription namemaxMessages - the maximum number of pulled messagesreturnImmediately - returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessagespublic <T> List<ConvertedAcknowledgeablePubsubMessage<T>> pullAndConvert(String subscription, Integer maxMessages, Boolean returnImmediately, Class<T> payloadType)
PubSubSubscriberOperationspullAndConvert in interface PubSubSubscriberOperationsT - the type of the payloadsubscription - the subscription namemaxMessages - the maximum number of pulled messagesreturnImmediately - returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessagespayloadType - the type to which the payload of the Pub/Sub messages should be convertedpublic List<com.google.pubsub.v1.PubsubMessage> pullAndAck(String subscription, Integer maxMessages, Boolean returnImmediately)
PubSubSubscriberOperationspullAndAck in interface PubSubSubscriberOperationssubscription - the subscription namemaxMessages - the maximum number of pulled messagesreturnImmediately - returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessagespublic com.google.pubsub.v1.PubsubMessage pullNext(String subscription)
PubSubSubscriberOperationspullNext in interface PubSubSubscriberOperationssubscription - the subscription namenull if none exists in the subscriptionpublic SubscriberFactory getSubscriberFactory()
public org.springframework.util.concurrent.ListenableFuture<Void> ack(Collection<AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages)
ack in interface PubSubSubscriberOperationsacknowledgeablePubsubMessages - messages, potentially from different subscriptions.ListenableFuture indicating overall success or failure.public org.springframework.util.concurrent.ListenableFuture<Void> nack(Collection<AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages)
nack in interface PubSubSubscriberOperationsacknowledgeablePubsubMessages - messages, potentially from different subscriptions.ListenableFuture indicating overall success or failure.public org.springframework.util.concurrent.ListenableFuture<Void> modifyAckDeadline(Collection<AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages, int ackDeadlineSeconds)
modifyAckDeadline in interface PubSubSubscriberOperationsacknowledgeablePubsubMessages - messages, potentially from different subscriptions.ackDeadlineSeconds - the new ack deadline in seconds. A deadline of 0 effectively nacks the messages.ListenableFuture indicating overall success or failure.public void destroy()
destroy in interface org.springframework.beans.factory.DisposableBeanCopyright © 2019 Pivotal Software, Inc.. All rights reserved.