Search in sources :

Example 1 with InstantiatingExecutorProvider

use of com.google.api.gax.core.InstantiatingExecutorProvider in project google-cloud-java by GoogleCloudPlatform.

the class PubsubBenchWrapperImpl method recv.

public void recv(PubsubRecv request, StreamObserver<EmptyResponse> responseObserver) {
    System.out.println("recv has been called");
    ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of("some-project", request.getSubName());
    Subscriber subscriber = null;
    try {
        InstantiatingExecutorProvider executorProvider = InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(1).build();
        subscriber = Subscriber.newBuilder(subscriptionName, new SimpleReceiver()).setExecutorProvider(executorProvider).build();
        subscriber.startAsync().awaitRunning();
        // Allow the subscriber to run indefinitely unless an unrecoverable error occurs.
        subscriber.awaitTerminated();
    } catch (IllegalStateException e) {
        System.out.println("Subscriber unexpectedly stopped: " + e);
    }
    EmptyResponse reply = EmptyResponse.newBuilder().build();
    responseObserver.onNext(reply);
    responseObserver.onCompleted();
}
Also used : ProjectSubscriptionName(com.google.pubsub.v1.ProjectSubscriptionName) Subscriber(com.google.cloud.pubsub.v1.Subscriber) InstantiatingExecutorProvider(com.google.api.gax.core.InstantiatingExecutorProvider)

Aggregations

InstantiatingExecutorProvider (com.google.api.gax.core.InstantiatingExecutorProvider)1 Subscriber (com.google.cloud.pubsub.v1.Subscriber)1 ProjectSubscriptionName (com.google.pubsub.v1.ProjectSubscriptionName)1