public class PubSubTemplate extends Object implements PubSubOperations, org.springframework.beans.factory.InitializingBean
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 that uses SimplePubSubMessageConverter
to serialize and deserialize payloads. |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
PubSubAcknowledger |
getAcknowledger() |
PubSubMessageConverter |
getMessageConverter() |
PublisherFactory |
getPublisherFactory() |
SubscriberFactory |
getSubscriberFactory() |
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.
|
com.google.pubsub.v1.PubsubMessage |
pullNext(String subscription)
Pull and auto-acknowledge a message from a Google Cloud Pub/Sub subscription.
|
PubSubTemplate |
setMessageConverter(PubSubMessageConverter messageConverter) |
com.google.cloud.pubsub.v1.Subscriber |
subscribe(String subscription,
com.google.cloud.pubsub.v1.MessageReceiver messageHandler)
Add a callback method to an existing subscription.
|
public PubSubTemplate(PublisherFactory publisherFactory, SubscriberFactory subscriberFactory)
PubSubTemplate
constructor that uses SimplePubSubMessageConverter
to serialize and deserialize payloads.publisherFactory
- the Publisher
factory to
publish to topicssubscriberFactory
- the Subscriber
factory
to subscribe to subscriptionspublic PubSubMessageConverter getMessageConverter()
public PubSubTemplate 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 PubSubOperations
topic
- the name of an existing topicpayload
- an object that will be serialized and sentpublic <T> org.springframework.util.concurrent.ListenableFuture<String> publish(String topic, T payload)
PubSubOperations
publish
in interface PubSubOperations
topic
- the name of an existing topicpayload
- an object that will be serialized and sentpublic org.springframework.util.concurrent.ListenableFuture<String> publish(String topic, com.google.pubsub.v1.PubsubMessage pubsubMessage)
PubSubOperations
publish
in interface PubSubOperations
topic
- the name of an existing topicpubsubMessage
- a Google Cloud Pub/Sub API messagepublic com.google.cloud.pubsub.v1.Subscriber subscribe(String subscription, com.google.cloud.pubsub.v1.MessageReceiver messageHandler)
PubSubOperations
The created Subscriber
is returned so it can be stopped.
subscribe
in interface PubSubOperations
subscription
- the name of an existing subscriptionmessageHandler
- the callback method triggered when new messages arrivepublic List<AcknowledgeablePubsubMessage> pull(String subscription, Integer maxMessages, Boolean returnImmediately)
PubSubOperations
pull
in interface PubSubOperations
subscription
- the subscription namemaxMessages
- the maximum number of pulled messagesreturnImmediately
- returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessages
public List<com.google.pubsub.v1.PubsubMessage> pullAndAck(String subscription, Integer maxMessages, Boolean returnImmediately)
PubSubOperations
pullAndAck
in interface PubSubOperations
subscription
- the subscription namemaxMessages
- the maximum number of pulled messagesreturnImmediately
- returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessages
public com.google.pubsub.v1.PubsubMessage pullNext(String subscription)
PubSubOperations
pullNext
in interface PubSubOperations
subscription
- the subscription namenull
if none exists in the subscriptionpublic void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
public PublisherFactory getPublisherFactory()
public SubscriberFactory getSubscriberFactory()
public PubSubAcknowledger getAcknowledger()
Copyright © 2018 Pivotal Software, Inc.. All rights reserved.