use of com.google.api.gax.batching.FlowController.LimitExceededBehavior in project google-cloud-java by GoogleCloudPlatform.
the class PublisherSnippets method getPublisherWithCustomFlowControlSettings.
public Publisher getPublisherWithCustomFlowControlSettings(TopicName topicName) throws Exception {
// [START pubsub_publisher_flow_settings]
// Flow control settings restrict the number of outstanding publish requests
int maxOutstandingBatches = 20;
int maxOutstandingRequestBytes = 500000;
// override behavior on limits exceeded if needed, default behavior is to block
LimitExceededBehavior limitExceededBehavior = LimitExceededBehavior.ThrowException;
FlowControlSettings flowControlSettings = FlowControlSettings.newBuilder().setMaxOutstandingElementCount(maxOutstandingBatches).setMaxOutstandingRequestBytes(maxOutstandingRequestBytes).setLimitExceededBehavior(limitExceededBehavior).build();
Publisher publisher = Publisher.defaultBuilder(topicName).setFlowControlSettings(flowControlSettings).build();
// [END pubsub_publisher_flow_settings]
return publisher;
}
Aggregations