Search in sources :

Example 1 with ExecutorProvider

use of com.google.api.gax.grpc.ExecutorProvider in project google-cloud-java by GoogleCloudPlatform.

the class PublisherSnippets method getSingleThreadedPublisher.

public Publisher getSingleThreadedPublisher(TopicName topicName) throws Exception {
    // [START pubsub_publisher_single_threaded]
    // create a publisher with a single threaded executor
    ExecutorProvider executorProvider = InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(1).build();
    Publisher publisher = Publisher.defaultBuilder(topicName).setExecutorProvider(executorProvider).build();
    // [END pubsub_publisher_single_threaded]
    return publisher;
}
Also used : Publisher(com.google.cloud.pubsub.spi.v1.Publisher) ExecutorProvider(com.google.api.gax.grpc.ExecutorProvider) InstantiatingExecutorProvider(com.google.api.gax.grpc.InstantiatingExecutorProvider)

Example 2 with ExecutorProvider

use of com.google.api.gax.grpc.ExecutorProvider in project google-cloud-java by GoogleCloudPlatform.

the class SubscriberSnippets method createSingleThreadedSubscriber.

private Subscriber createSingleThreadedSubscriber() throws Exception {
    // [START pubsub_subscriber_single_threaded]
    // provide a separate executor service for polling
    ExecutorProvider executorProvider = InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(1).build();
    Subscriber subscriber = Subscriber.defaultBuilder(subscriptionName, receiver).setExecutorProvider(executorProvider).build();
    // [END pubsub_subscriber_single_threaded]
    return subscriber;
}
Also used : Subscriber(com.google.cloud.pubsub.spi.v1.Subscriber) ExecutorProvider(com.google.api.gax.grpc.ExecutorProvider) InstantiatingExecutorProvider(com.google.api.gax.grpc.InstantiatingExecutorProvider)

Aggregations

ExecutorProvider (com.google.api.gax.grpc.ExecutorProvider)2 InstantiatingExecutorProvider (com.google.api.gax.grpc.InstantiatingExecutorProvider)2 Publisher (com.google.cloud.pubsub.spi.v1.Publisher)1 Subscriber (com.google.cloud.pubsub.spi.v1.Subscriber)1