use of com.google.api.gax.batching.FlowControlSettings 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;
}
use of com.google.api.gax.batching.FlowControlSettings in project google-cloud-java by GoogleCloudPlatform.
the class SubscriberSnippets method createSubscriberWithCustomFlowSettings.
private Subscriber createSubscriberWithCustomFlowSettings() throws Exception {
// [START pubsub_subscriber_flow_settings]
int maxMessageCount = 10;
// Configure max number of messages to be pulled
FlowControlSettings flowControlSettings = FlowControlSettings.newBuilder().setMaxOutstandingElementCount(maxMessageCount).build();
Subscriber subscriber = Subscriber.defaultBuilder(subscriptionName, receiver).setFlowControlSettings(flowControlSettings).build();
// [END pubsub_subscriber_flow_settings]
return subscriber;
}
Aggregations