Unable to connect to local Pub/Sub emulator with PubSub.V1
See original GitHub issueI’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:
- Created 6 years ago
- Comments:8
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.
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.