public class PubSubTemplate extends Object implements PubSubOperations
PubSubOperations.
The main Google Cloud Pub/Sub integration component for publishing to topics and consuming messages from subscriptions asynchronously or by pulling.
| Constructor and Description |
|---|
PubSubTemplate(PublisherFactory publisherFactory,
SubscriberFactory subscriberFactory)
Default
PubSubTemplate constructor. |
PubSubTemplate(PubSubPublisherTemplate pubSubPublisherTemplate,
PubSubSubscriberTemplate pubSubSubscriberTemplate)
Default
PubSubTemplate constructor that uses a PubSubPublisherTemplate and a
PubSubSubscriberTemplate. |
| Modifier and Type | Method and Description |
|---|---|
org.springframework.util.concurrent.ListenableFuture<Void> |
ack(Collection<? extends AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages)
Acknowledge a batch of messages.
|
PubSubMessageConverter |
getMessageConverter() |
PublisherFactory |
getPublisherFactory() |
PubSubPublisherTemplate |
getPubSubPublisherTemplate() |
PubSubSubscriberTemplate |
getPubSubSubscriberTemplate() |
SubscriberFactory |
getSubscriberFactory() |
org.springframework.util.concurrent.ListenableFuture<Void> |
modifyAckDeadline(Collection<? extends AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages,
int ackDeadlineSeconds)
Modify the ack deadline of a batch of messages.
|
org.springframework.util.concurrent.ListenableFuture<Void> |
nack(Collection<? extends AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages)
Negatively acknowledge a batch of messages.
|
org.springframework.util.concurrent.ListenableFuture<String> |
publish(String topic,
com.google.pubsub.v1.PubsubMessage pubsubMessage)
Send a message to Pub/Sub.
|
<T> org.springframework.util.concurrent.ListenableFuture<String> |
publish(String topic,
T payload)
Send a message to Pub/Sub.
|
<T> org.springframework.util.concurrent.ListenableFuture<String> |
publish(String topic,
T payload,
Map<String,String> headers)
Uses the configured message converter to first convert the payload and headers to a
PubsubMessage and then publish it. |
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.
|
org.springframework.util.concurrent.ListenableFuture<List<com.google.pubsub.v1.PubsubMessage>> |
pullAndAckAsync(String subscription,
Integer maxMessages,
Boolean returnImmediately)
Asynchronously 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.
|
<T> org.springframework.util.concurrent.ListenableFuture<List<ConvertedAcknowledgeablePubsubMessage<T>>> |
pullAndConvertAsync(String subscription,
Integer maxMessages,
Boolean returnImmediately,
Class<T> payloadType)
Asynchronously pull a number of messages from a Google Cloud Pub/Sub subscription and convert
them to Spring messages with the desired payload type.
|
org.springframework.util.concurrent.ListenableFuture<List<AcknowledgeablePubsubMessage>> |
pullAsync(String subscription,
Integer maxMessages,
Boolean returnImmediately)
Asynchronously pull a number of messages from a Google Cloud Pub/Sub subscription.
|
com.google.pubsub.v1.PubsubMessage |
pullNext(String subscription)
Pull and auto-acknowledge a message from a Google Cloud Pub/Sub subscription.
|
org.springframework.util.concurrent.ListenableFuture<com.google.pubsub.v1.PubsubMessage> |
pullNextAsync(String subscription)
Asynchronously pull and auto-acknowledge a message from a Google Cloud Pub/Sub subscription.
|
void |
setMessageConverter(PubSubMessageConverter messageConverter) |
com.google.cloud.pubsub.v1.Subscriber |
subscribe(String subscription,
Consumer<BasicAcknowledgeablePubsubMessage> messageConsumer)
Add a callback method to an existing subscription.
|
<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 PubSubTemplate(PublisherFactory publisherFactory, SubscriberFactory subscriberFactory)
PubSubTemplate constructor.publisherFactory - the Publisher factory to publish to
topics.subscriberFactory - the Subscriber factory to subscribe
to subscriptions.public PubSubTemplate(PubSubPublisherTemplate pubSubPublisherTemplate, PubSubSubscriberTemplate pubSubSubscriberTemplate)
PubSubTemplate constructor that uses a PubSubPublisherTemplate and a
PubSubSubscriberTemplate.pubSubPublisherTemplate - the PubSubPublisherTemplate to publish to topics.pubSubSubscriberTemplate - the PubSubSubscriberTemplate to subscribe to
subscriptions or pull messagespublic PubSubPublisherTemplate getPubSubPublisherTemplate()
public PubSubSubscriberTemplate getPubSubSubscriberTemplate()
public PubSubMessageConverter getMessageConverter()
public void setMessageConverter(PubSubMessageConverter messageConverter)
public <T> org.springframework.util.concurrent.ListenableFuture<String> publish(String topic, T payload, Map<String,String> headers)
PubsubMessage and then publish it.publish in interface PubSubPublisherOperationsT - the type of the payload to publishtopic - short topic name, e.g., "topicName", or the fully-qualified topic name in the
projects/[project_name]/topics/[topic_name] formatpayload - an object that will be serialized and sentheaders - the headers to publishpublic <T> org.springframework.util.concurrent.ListenableFuture<String> publish(String topic, T payload)
PubSubPublisherOperationspublish in interface PubSubPublisherOperationsT - the type of the payload to publishtopic - short topic name, e.g., "topicName", or the fully-qualified topic name in the
projects/[project_name]/topics/[topic_name] formatpayload - an object that will be serialized and sentpublic org.springframework.util.concurrent.ListenableFuture<String> publish(String topic, com.google.pubsub.v1.PubsubMessage pubsubMessage)
PubSubPublisherOperationspublish in interface PubSubPublisherOperationstopic - short topic name, e.g., "topicName", or the fully-qualified topic name in the
projects/[project_name]/topics/[topic_name] formatpubsubMessage - a Google Cloud Pub/Sub API messagepublic 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 - short subscription name, e.g., "subscriptionName", or the
fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] formatmessageConsumer - 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 - short subscription name, e.g., "subscriptionName", or the
fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] formatmessageConsumer - 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 - short subscription name, e.g., "subscriptionName", or the
fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] formatmaxMessages - the maximum number of pulled messages. If this value is null then up to
Integer.MAX_VALUE messages will be requested.returnImmediately - returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessages. Setting this parameter to true is not
recommended as it may result in long delays in message delivery.public org.springframework.util.concurrent.ListenableFuture<List<AcknowledgeablePubsubMessage>> pullAsync(String subscription, Integer maxMessages, Boolean returnImmediately)
PubSubSubscriberOperationspullAsync in interface PubSubSubscriberOperationssubscription - short subscription name, e.g., "subscriptionName", or the
fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] formatmaxMessages - the maximum number of pulled messages. If this value is null then up to
Integer.MAX_VALUE messages will be requested.returnImmediately - returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessages. Setting this parameter to true is not
recommended as it may result in long delays in message delivery.public <T> List<ConvertedAcknowledgeablePubsubMessage<T>> pullAndConvert(String subscription, Integer maxMessages, Boolean returnImmediately, Class<T> payloadType)
PubSubSubscriberOperationspullAndConvert in interface PubSubSubscriberOperationsT - the type of the payloadsubscription - short subscription name, e.g., "subscriptionName", or the
fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] formatmaxMessages - the maximum number of pulled messages. If this value is null then up to
Integer.MAX_VALUE messages will be requested.returnImmediately - returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessages. Setting this parameter to true is not
recommended as it may result in long delays in message delivery.payloadType - the type to which the payload of the Pub/Sub messages should be convertedpublic <T> org.springframework.util.concurrent.ListenableFuture<List<ConvertedAcknowledgeablePubsubMessage<T>>> pullAndConvertAsync(String subscription, Integer maxMessages, Boolean returnImmediately, Class<T> payloadType)
PubSubSubscriberOperationspullAndConvertAsync in interface PubSubSubscriberOperationsT - the type of the payloadsubscription - short subscription name, e.g., "subscriptionName", or the
fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] formatmaxMessages - the maximum number of pulled messages. If this value is null then up to
Integer.MAX_VALUE messages will be requested.returnImmediately - returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessages. Setting this parameter to true is not
recommended as it may result in long delays in message delivery.payloadType - 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 - short subscription name, e.g., "subscriptionName", or the
fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] formatmaxMessages - the maximum number of pulled messages. If this value is null then up to
Integer.MAX_VALUE messages will be requested.returnImmediately - returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessages. Setting this parameter to true is not
recommended as it may result in long delays in message delivery.public org.springframework.util.concurrent.ListenableFuture<List<com.google.pubsub.v1.PubsubMessage>> pullAndAckAsync(String subscription, Integer maxMessages, Boolean returnImmediately)
PubSubSubscriberOperationspullAndAckAsync in interface PubSubSubscriberOperationssubscription - short subscription name, e.g., "subscriptionName", or the
fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] formatmaxMessages - the maximum number of pulled messages. If this value is null then up to
Integer.MAX_VALUE messages will be requested.returnImmediately - returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessages. Setting this parameter to true is not
recommended as it may result in long delays in message delivery.public com.google.pubsub.v1.PubsubMessage pullNext(String subscription)
PubSubSubscriberOperationspullNext in interface PubSubSubscriberOperationssubscription - short subscription name, e.g., "subscriptionName", or the
fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] formatnull if none exists in the subscriptionpublic org.springframework.util.concurrent.ListenableFuture<com.google.pubsub.v1.PubsubMessage> pullNextAsync(String subscription)
PubSubSubscriberOperationspullNextAsync in interface PubSubSubscriberOperationssubscription - short subscription name, e.g., "subscriptionName", or the
fully-qualified subscription name in the projects/[project_name]/subscriptions/[subscription_name] formatnull if none exists in the subscriptionpublic org.springframework.util.concurrent.ListenableFuture<Void> ack(Collection<? extends AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages)
PubSubSubscriberOperationsack in interface PubSubSubscriberOperationsacknowledgeablePubsubMessages - messages to be acknowledgedListenableFuture<Void> the ListenableFuture for the asynchronous executionpublic org.springframework.util.concurrent.ListenableFuture<Void> nack(Collection<? extends AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages)
PubSubSubscriberOperationsnack in interface PubSubSubscriberOperationsacknowledgeablePubsubMessages - messages to be negatively acknowledgedListenableFuture<Void> the ListenableFuture for the asynchronous executionpublic org.springframework.util.concurrent.ListenableFuture<Void> modifyAckDeadline(Collection<? extends AcknowledgeablePubsubMessage> acknowledgeablePubsubMessages, int ackDeadlineSeconds)
PubSubSubscriberOperationsmodifyAckDeadline in interface PubSubSubscriberOperationsacknowledgeablePubsubMessages - messages to be modifiedackDeadlineSeconds - the new ack deadline in seconds. A deadline of 0 effectively nacks
the messages.ListenableFuture<Void> the ListenableFuture for the asynchronous executionpublic PublisherFactory getPublisherFactory()
public SubscriberFactory getSubscriberFactory()
Copyright © 2024. All rights reserved.