Search in sources :

Example 1 with LimitExceededBehavior

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;
}
Also used : FlowControlSettings(com.google.api.gax.batching.FlowControlSettings) Publisher(com.google.cloud.pubsub.spi.v1.Publisher) LimitExceededBehavior(com.google.api.gax.batching.FlowController.LimitExceededBehavior)

Aggregations

FlowControlSettings (com.google.api.gax.batching.FlowControlSettings)1 LimitExceededBehavior (com.google.api.gax.batching.FlowController.LimitExceededBehavior)1 Publisher (com.google.cloud.pubsub.spi.v1.Publisher)1