Nodejs-pubsub: Using nodejs-pubsub client in multi tenant application

Created on 14 May 2020  路  2Comments  路  Source: googleapis/nodejs-pubsub

Hi,

Background:
We are building a Multi tenant node js application where user can come in with their credentials and use our app to interact with Google pub sub.
Few points to be noted:

  • The application we are trying to build is a multi tenant node js application.
  • There will be a single node process running in which multiple users can come with their access tokens and use the application to interact with cloud pub sub for integration purpose.

Question:

  1. Is this client capable to be used in multi tenant single node process ?
  2. Can we instantiate multiple client belonging to different service accounts in a single node process ?

Please suggest.
Thanks.

pubsub question

Most helpful comment

@nazimkh At a glance, you should be able to make separate PubSub objects and publish for different clients. I don't know the full stack offhand, so I'm not 100% sure of that, but it makes sense to me.

The way to get different authentication for each one is to pass in the credentials manually instead of letting the library pull it from environment variables. So you'd create one more or less like this:

const pubsub = new PubSub({
  projectId: 'yourProject',
  credentials: {
    client_email: "[email protected]",
    private_key: "-----BEGIN PRIVATE KEY-----\n etc",
  },
});

You can find those client_email and private_key values from the downloaded JSON key that you get from the GCP web console. Instead of credentials you can also use keyFilename and pass a path to the JSON key.

If that works for you, go ahead and close the issue out, or let me know if you need further help.

All 2 comments

@nazimkh At a glance, you should be able to make separate PubSub objects and publish for different clients. I don't know the full stack offhand, so I'm not 100% sure of that, but it makes sense to me.

The way to get different authentication for each one is to pass in the credentials manually instead of letting the library pull it from environment variables. So you'd create one more or less like this:

const pubsub = new PubSub({
  projectId: 'yourProject',
  credentials: {
    client_email: "[email protected]",
    private_key: "-----BEGIN PRIVATE KEY-----\n etc",
  },
});

You can find those client_email and private_key values from the downloaded JSON key that you get from the GCP web console. Instead of credentials you can also use keyFilename and pass a path to the JSON key.

If that works for you, go ahead and close the issue out, or let me know if you need further help.

@feywind it works properly. Thanks

Was this page helpful?
0 / 5 - 0 ratings