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. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
PublisherFactory |
getPublisherFactory() |
SubscriberFactory |
getSubscriberFactory() |
org.springframework.util.concurrent.ListenableFuture<String> |
publish(String topic,
byte[] payload,
Map<String,String> headers)
Send a message to Pub/Sub.
|
org.springframework.util.concurrent.ListenableFuture<String> |
publish(String topic,
com.google.protobuf.ByteString payload,
Map<String,String> headers)
Send a message to Pub/Sub.
|
org.springframework.util.concurrent.ListenableFuture<String> |
publish(String topic,
com.google.pubsub.v1.PubsubMessage pubsubMessage)
Send a message to Pub/Sub.
|
org.springframework.util.concurrent.ListenableFuture<String> |
publish(String topic,
String payload,
Map<String,String> headers)
Send a message to Pub/Sub.
|
org.springframework.util.concurrent.ListenableFuture<String> |
publish(String topic,
String payload,
Map<String,String> headers,
Charset charset)
Send a message to Pub/Sub.
|
List<com.google.pubsub.v1.PubsubMessage> |
pull(String subscription,
Integer maxMessages,
Boolean returnImmediately,
com.google.api.gax.retrying.RetrySettings retrySettings)
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.
|
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.publisherFactory - the Publisher factory to
publish to topicssubscriberFactory - the Subscriber factory to
subscribe to subscriptionspublic org.springframework.util.concurrent.ListenableFuture<String> publish(String topic, String payload, Map<String,String> headers)
PubSubOperationspublish in interface PubSubOperationstopic - the name of an existing topicpayload - the message String payloadheaders - map of String to String headerspublic org.springframework.util.concurrent.ListenableFuture<String> publish(String topic, String payload, Map<String,String> headers, Charset charset)
PubSubOperationspublish in interface PubSubOperationstopic - the name of an existing topicpayload - the message String payloadheaders - map of String to String headerscharset - charset to decode the payloadpublic org.springframework.util.concurrent.ListenableFuture<String> publish(String topic, byte[] payload, Map<String,String> headers)
PubSubOperationspublish in interface PubSubOperationstopic - the name of an existing topicpayload - the message payload in bytesheaders - map of String to String headerspublic org.springframework.util.concurrent.ListenableFuture<String> publish(String topic, com.google.protobuf.ByteString payload, Map<String,String> headers)
PubSubOperationspublish in interface PubSubOperationstopic - the name of an existing topicpayload - the message payload on the PubsubMessage payload formatheaders - map of String to String headerspublic org.springframework.util.concurrent.ListenableFuture<String> publish(String topic, com.google.pubsub.v1.PubsubMessage pubsubMessage)
PubSubOperationspublish in interface PubSubOperationstopic - 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)
PubSubOperationsThe created Subscriber is returned so it can be stopped.
subscribe in interface PubSubOperationssubscription - the name of an existing subscriptionmessageHandler - the callback method triggered when new messages arrivepublic List<com.google.pubsub.v1.PubsubMessage> pull(String subscription, Integer maxMessages, Boolean returnImmediately, com.google.api.gax.retrying.RetrySettings retrySettings)
PubSubOperationspull in interface PubSubOperationssubscription - the subscription namemaxMessages - the maximum number of pulled messagesreturnImmediately - returns immediately even if subscription doesn't contain enough
messages to satisfy maxMessagesretrySettings - the timeout and retry setting for the pull requestpublic com.google.pubsub.v1.PubsubMessage pullNext(String subscription)
PubSubOperationspullNext in interface PubSubOperationssubscription - the subscription namenull if none exists in the subscriptionpublic void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanExceptionpublic PublisherFactory getPublisherFactory()
public SubscriberFactory getSubscriberFactory()
Copyright © 2018 Pivotal Software, Inc.. All rights reserved.