question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to connect to local Pub/Sub emulator with PubSub.V1

See original GitHub issue

I’m using the following code to try connecting to the Pub/Sub emulator running on localhost. It’s basically a direct copy of the example code with the ServiceEndpoint changed.

TopicName topicName = new TopicName(projectId, topicId);
var endpoint = new ServiceEndpoint("localhost", 8085);
SubscriberClient subscriber = await SubscriberClient.CreateAsync(endpoint);
SubscriptionName subscriptionName = new SubscriptionName(projectId, "test-sub");
subscriber.CreateSubscription(subscriptionName, topicName, pushConfig: null, ackDeadlineSeconds: 60);

No errors are thrown but no messages are received either. Looking at the emulator logs I see:

[pubsub] INFO: Adding handler(s) to newly registered Channel.
[pubsub] Jan 08, 2018 10:50:10 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFO: Detected non-HTTP/2 connection.
[pubsub] Jan 08, 2018 10:50:10 PM io.gapi.emulators.netty.NotFoundHandler handleRequest
[pubsub] INFO: Unknown request URI: /bad-request

A quick google let me to https://stackoverflow.com/questions/43657112/creating-topic-on-pubsub-emulator suggesting that the solution for the Java library is to create a custom ChannelProvider and have it use NegotiationType.PLAINTEXT as this is required by the emulator.

This led me to try using insecure GRPC which works for the SimpleSubscriber:

var settings = new SimpleSubscriber.ClientCreationSettings(null, null, ChannelCredentials.Insecure, endpoint);
SimpleSubscriber simpleSubscriber = await SimpleSubscriber.CreateAsync(subscriptionName, settings);

but not the SubscriberClient needed to create a topic. I see a way to change the CallCredentials for the SubscriberClient but can’t figure out how to switch it to insecure. This may be to my relative lack of understanding of the gRPC setup.

Any insight on how to get this working?

Also an example of using these libraries with the emulators would be helpful. It’s one of the first places developers are going to start experimenting with the libraries and the experience so far hasn’t been smooth for me (not specific to the c# libraries, am testing with others as well).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
jskeetcommented, Jan 9, 2018

See https://googlecloudplatform.github.io/google-cloud-dotnet/docs/faq.html#how-can-i-use-emulators for this - basically you need to create a channel and pass that into SubscriberClient.Create.

Please check whether this works for you - I’ll assign this to Chris to look into if you have any more issues.

1reaction
jskeetcommented, Sep 12, 2019

Well there’s nothing conditional in your code, so yes, it will still run. If you want to stop it from running when the environment variable is missing or empty, you’d write code to do that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't reach GCP PubSub Emulator
Through Postman, uncheck the Connection key. The reason why it works through curl is because you don't have Connection metadata.
Read more >
Testing apps locally with the emulator - Cloud Pub/Sub
Start the emulator by invoking pubsub start from a command prompt. Before running the command, replace PUBSUB_PROJECT_ID with a valid Google Cloud project...
Read more >
Push isn't working with pubsub emulator
to Google Cloud Pub/Sub Discussions. Hello! I'm trying to test locally withe the emulator which works fine for create topics/subscriptions, publishing and ...
Read more >
Pub/Sub local emulator
Pub/Sub is a nice tool provided by GCP. It is really handy and can help you with the messaging challenges you application might...
Read more >
How to connect your Spring Cloud Application to a local ...
Start the emulator by invoking pubsub start from a command prompt. Before running the command, replace PUBSUB_PROJECT_ID with a valid Google ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found