Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PubSub]: Program Hangs When PubSub Emulator Is Down #891

Closed
mikail-khan opened this issue Oct 26, 2021 · 1 comment
Closed

[PubSub]: Program Hangs When PubSub Emulator Is Down #891

mikail-khan opened this issue Oct 26, 2021 · 1 comment
Assignees
Labels
api: pubsub Issues related to the googleapis/java-pubsub API. type: question Request for information or clarification. Not an issue.

Comments

@mikail-khan
Copy link

mikail-khan commented Oct 26, 2021

Environment details

  1. PubSub
  2. OS type and version:Linux 5.14.10-1-MANJARO Add #1 SMP PREEMPT x86_64 GNU/Linu
  3. Java version: Java 16
  4. pubsub version(s):1.114.7

Steps to reproduce

  1. Create a simple pubsub program as per the guide here: https://cloud.google.com/pubsub/docs/publisher
  2. Ensure that you create the Publisher as follows so that the emulator is used: https://github.com/googleapis/google-cloud-java/blob/7bb326f59974a75198a5fb6a4d15f407b51bdd0a/google-cloud-examples/src/main/java/com/google/cloud/examples/pubsub/snippets/UsePubSubEmulatorSnippet.java#L41

Code

package example;

import com.google.api.core.ApiFuture;
import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.rpc.FixedTransportChannelProvider;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.cloud.pubsub.v1.Publisher;
import com.google.protobuf.ByteString;
import com.google.pubsub.v1.PubsubMessage;
import com.google.pubsub.v1.TopicName;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class Hello {
    public static void main(String... args) throws Exception {
        // TODO(developer): Replace these variables before running the sample.
        String projectId = "some-project";
        String topicId = "foo";

        publisherExample(projectId, topicId);
    }

    public static void publisherExample(String projectId, String topicId)
            throws IOException, ExecutionException, InterruptedException {
        TopicName topicName = TopicName.of(projectId, topicId);

        String hostport = System.getenv("PUBSUB_EMULATOR_HOST");
        ManagedChannel channel = ManagedChannelBuilder.forTarget(hostport).usePlaintext().build();
        TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));
        CredentialsProvider credentialsProvider = NoCredentialsProvider.create();


        // Set the channel and credentials provider when creating a `Publisher`.
        // Similarly for Subscriber
        Publisher publisher =
                Publisher.newBuilder(topicName)
                        .setChannelProvider(channelProvider)
                        .setCredentialsProvider(credentialsProvider)
                        .build();

        String message = "Hello World!";
        ByteString data = ByteString.copyFromUtf8(message);
        PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(data).build();

        // Once published, returns a server-assigned message id (unique within the topic)
        ApiFuture<String> messageIdFuture = publisher.publish(pubsubMessage);
        String messageId = messageIdFuture.get();
        System.out.println("Published message ID: " + messageId);
    }

}

Stack trace

No Stack Trace - that's the problem

Any additional information below

I have followed the guides to create a simple publisher and tested it against a local running PubSub emulator. When the emulator is running, everything is fine and works accordingly. However, to test that my program handles pathological situations, I shut down the emulator and ran my program. My program hangs. I was expecting some sort of exception to be thrown to indicate that the a channel/connection could not be created between my program and the emulator but nothing happens.

Why does the program hang? Is it retrying (I couldn't tell from looking at the implementation)? If it is retrying what are the default RetrySettings?

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/java-pubsub API. label Oct 26, 2021
@hannahrogers-google hannahrogers-google added the type: question Request for information or clarification. Not an issue. label Oct 27, 2021
@hannahrogers-google
Copy link
Contributor

Hi @mikail-khan, you are correct, publishes are retried by default. You can see our documentation for the default retry settings, and how to configure your own retry settings: https://cloud.google.com/pubsub/docs/samples/pubsub-publisher-retry-settings#pubsub_publisher_retry_settings-java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/java-pubsub API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants