Thursday, 1 June 2017

Pub/Sub conflicting documentation?

I read in the following link, that I must start a pub/sub instance locally with the command: gcloud beta emulators pubsub env-init && gcloud beta emulators pubsub start:

https://cloud.google.com/pubsub/docs/emulator

This is fine, and the instance is up and running.

What I don't understand is when I start up node.js application it doesn't seem to interact with this instance.

I'm able to get the following working without the instance running locally:

  const subscription = pubsub.subscription(topicName);
  // Register a listener for `message` events.
  subscription.on('message', (message) => {
    console.log('->', message);
  });
  const results = await pubsub.topic('my-new-topic').publish('my message');
  const messageIds = results[0];
  console.log(`Message ${messageIds[0]} published.`);

I thought that it might go up against my project on the cloud however since I also ran the gcloud beta emulators pubsub env-init that it should use the local one. As said it seems to be working even though I don't have it started.

I wonder if I've misunderstood the how it works in local development. The following is what I've read.

  1. Create Project
  2. Enable Pub/Sub
  3. Download SDK install and initialize
  4. Install NPM library in Node.js application
  5. Set environmental variable via gcloud beta emulators pubsub env-init
  6. Start the local pub/sub emulator via gcloud beta emulators pubsub start
  7. Start Node.js application, watch it connect, get topic, publish, subscribe etc.

I wish google would just do a simple bullet list sometimes and make the deep reading optional.



via Karl Morrison

No comments:

Post a Comment