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.

Pubsub emulator with v1 doesn't work

See original GitHub issue

Environment details

  • OS: MacOS
  • Node.js version: 12
  • npm version: Latest yarn 1.x
  • @google-cloud/pubsub version: Latest

Steps to reproduce

Using the synchronous pull example, the PusSub emulator doesn’t seem to be working. It’s as the env variable PUBSUB_EMULATOR_HOST is being ignored.

Also,

with the default emulator local host (localhost:8085), if I do:

const subClient = new v1.SubscriberClient({
  apiEndpoint: 'localhost:8085',
});

I am getting the error:

Error: Failed to parse target localhost:8085:443
        at Function.getDefaultAuthority (/node_modules/@grpc/grpc-js/src/resolver-dns.ts:313:11)
        at Object.getDefaultAuthority (/node_modules/@grpc/grpc-js/src/resolver.ts:134:28)
        at new ChannelImplementation (/node_modules/@grpc/grpc-js/src/channel.ts:199:31)
        at new Client (/node_modules/@grpc/grpc-js/src/client.ts:82:30)
        at new ServiceClientImpl (/node_modules/@grpc/grpc-js/src/make-client.ts:104:3)
        at GrpcClient.createStub (/node_modules/google-gax/src/grpc.ts:306:18)
        at processTicksAndRejections (internal/process/task_queues.js:93:5)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14

github_iconTop GitHub Comments

11reactions
rlucionicommented, Jul 27, 2020

@feywind this is also preventing my team from working with the Pub/Sub emulator locally, which makes development difficult. The workarounds proposed in https://github.com/googleapis/nodejs-pubsub/issues/346 don’t work.

7reactions
feywindcommented, Aug 3, 2020

Here are some ways to work around this, based on my testing:

The simplest, but probably also the most prone to breakage over time (these aren’t the same types, but they do technically contain the same things):

const pubsubClient = new PubSub();
const subClient = new v1.SubscriberClient(pubsubClient.options);

That will actually pick up the emulator environment variable in the normal way, since it’s just using the PubSub class’ init.

The specific members could be copied like so, to be a bit less breakable:

const pubsubClient = new PubSub();
const subClient = new v1.SubscriberClient({
  apiEndpoint: pubsubClient.options.apiEndpoint,
  port: pubsubClient.options.port,
  sslCreds: pubsubClient.options.sslCreds
});

You could also manually init the options, though I understand that wasn’t working for some:

const grpc = require('@grpc/grpc-js');

const subClient = new v1.SubscriberClient({
  apiEndpoint: 'localhost',
  port: '8085',
  sslCreds: grpc.credentials.createInsecure()
});

(And of course requires app logic, which may not be great.)

I also feel obligated to note that digging into PubSub.options isn’t really a public interface, so that could change whenever. I think probably the good long term solution for this is still the unified environment variables plus gapic client support for it. If it looks like the timeline is long on that, then I suppose another option would be to expose a “give me a client” method on PubSub.

Let me know if anything in there seems like it works, or if you have any ideas about making an interface that works better for you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing apps locally with the emulator | Cloud Pub/Sub ...
To develop and test your application locally, you can use the Pub/Sub emulator, which provides local emulation of the production Pub/Sub service. You...
Read more >
Push isn't working with pubsub emulator - Google Groups
Is there something I'm doing wrong or is it just that the emulator doesn't work with push subscriptions? Steeve's profile photo. Steeve.
Read more >
Can't reach GCP PubSub Emulator - Stack Overflow
I have setup the PubSub emulator to run a Python script locally pointing to it. The emulator is run following the tutorial and...
Read more >
Install, configure and integrate Local Emulator Suite - Firebase
The Firebase Local Emulator Suite can be installed and configured for different prototype and test environments, anything from one-off prototyping sessions ...
Read more >
The pubsub emulator doesn't deliver to push endpoints in the ...
Hi James, This is a known bug in the Pub/Sub emulator, the fix for which should come out in the next Cloud SDK...
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