Skip to content

Instantly share code, notes, and snippets.

@Alex-Werner
Last active January 16, 2023 14:45
Show Gist options
  • Save Alex-Werner/3cabab2ba09ea749a4c38b70326f9acf to your computer and use it in GitHub Desktop.
Save Alex-Werner/3cabab2ba09ea749a4c38b70326f9acf to your computer and use it in GitHub Desktop.
Moleculer JS NATS and Scaleway Messenging JS Code
const { ServiceBroker } = require('moleculer');
const { credsAuthenticator } = require('nats');
// Format of process.env.CREDENTIALS
// -----BEGIN NATS USER JWT-----
// ...
// ------END NATS USER JWT------
// -----BEGIN USER NKEY SEED-----
// SUAF...
// ------END USER NKEY SEED------
const broker = new ServiceBroker({
namespace: 'myspace',
nodeID: process.argv[2] || `myprocess-${address}-${process.pid}`,
transporter: {
type: 'NATS',
options: {
url: process.env.NATS_URL,
authenticator: credsAuthenticator(new TextEncoder().encode(process.env.CREDENTIALS)),
},
},
logger: console,
logLevel: process.env.LOGLEVEL,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment