Search in sources :

Example 1 with FlowControlSettings

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;
}
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)

Example 2 with FlowControlSettings

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

Aggregations

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