public class Publisher extends Object implements Closeable
Messages are gathered into batches, bounded by specified batch size and maximum latency. The publisher waits up to the specified max latency before sending a batch of messages for a topic. If enough messages to fill a batch are submitted before the max latency deadline, then the batch is sent immediately.
This batching strategy trades publish request quota for increased publishing latency as outgoing messages might spend more time waiting in the publisher per-topic queues before getting sent. The rationale for this strategy is to avoid (expensive and empirically observed) excessive numbers of very small batch publish requests during off-peak.
| Modifier and Type | Class and Description |
|---|---|
static class |
Publisher.Builder
A builder that can be used to build a
Publisher. |
static interface |
Publisher.Listener
A listener for monitoring operations performed by the
Publisher. |
static class |
Publisher.ListenerAdapter |
| Modifier and Type | Method and Description |
|---|---|
int |
batchSize()
Get the max Google Pub/Sub request batch size.
|
static Publisher.Builder |
builder()
Create a builder that can be used to build a
Publisher. |
void |
close()
Close this
Publisher. |
CompletableFuture<Void> |
closeFuture()
Get a future that is completed when this
Publisher is closed. |
int |
concurrency()
Get the concurrent Google Pub/Sub request limit.
|
int |
outstandingRequests()
Get the current number of outstanding (batch) requests to Google Pub/Sub.
|
int |
pendingTopics()
Get the current number of topics that are pending batch sending to Google Pub/Sub.
|
String |
project()
Get the Google Cloud project this
Publisher is publishing to. |
CompletableFuture<String> |
publish(String topic,
Message message)
Publish a message on a specific topic.
|
int |
queueSize()
Get the per-topic queue size.
|
int |
scheduledQueueSize()
Get the total number of scheduled requests.
|
int |
topicQueueSize(String topic)
Get the current queue size for the given topic name.
|
public CompletableFuture<String> publish(String topic, Message message)
topic - The topic name to publish on. Note that this is the short name, not the fully qualified name
including project. The project to publish on is configured using the Publisher.Builder.message - The message to publish.public void close()
close in interface Closeableclose in interface AutoCloseablepublic CompletableFuture<Void> closeFuture()
Publisher is closed.public int outstandingRequests()
public int scheduledQueueSize()
public int pendingTopics()
public int concurrency()
public int topicQueueSize(String topic)
topic - the topic namepublic int queueSize()
public int batchSize()
public static Publisher.Builder builder()
Publisher.Copyright © 2018. All rights reserved.