Pulse Publisher
A collection of utilities for interacting with Mozilla's Pulse.
Requirements
This is tested on and should run on any of node {7, 8, 10}
.
Usage
The source-code contains additional comments for each method.
let Exchanges = require('pulse-publisher');
let exchanges = new Exchanges({
name: 'myservice',
version: 'v1',
title: 'Title for Exchanges Docs',
description: [
'Description in **markdown**.',
'This will available in reference JSON',
].join(''),
});
exchanges.declare({
exchange: 'test-exchange',
name: 'testExchange',
title: 'Title for Exchange Docs',
description: [
'Description in **markdown**.',
'This will available in reference JSON',
].join(''),
schema: 'name-of-my-schema.yml',
messageBuilder: (message) => message,
routingKey: [
{
name: 'routingKeyKind',
summary: 'Routing key kind hardcoded to primary in primary routing-key',
constant: 'primary',
required: true,
}, {
name: 'someId',
summary: 'Brief docs',
required: true || false,
maxSize: 22,
multipleWords: true || false,
}, {
name: 'reserved',
summary: 'Space reserved for future use.',
multipleWords: true,
maxSize: 1,
}
],
routingKeyBuilder: (message) => {
return {
someId: message.someIdentifier,
};
},
CCBuilder: (message) => {
return message.routes.map(r => 'route.' + r);
},
});
let publisher = await exchanges.connect({
rootUrl: ...,
credentials: {
hostname: ..,
username: ..,
password: ..,
vhost: ..,
},
namespace: '...',
expires: '1 day',
validator: await schemaset.validator(rootUrl),
monitor: undefined,
});
await publisher.testExchange({someIdentifier: '...', routes: [], ...});
Note that all four values for credentials must be included.
Alternately, if using
taskcluster-lib-loader,
create a loader component that calls setup
, which will also publish the exchange reference:
publisher: {
requires: ['cfg', 'schemaset', 'monitor'],
setup: ({cfg, validator, monitor}) => exchanges.setup({
rootUrl: cfg.taskcluster.rootUrl,
credentials: cfg.pulse,
namespace: cfg.pulse.namespace,
expires: cfg.pulse.expires,
validator: await schemaset.validator(cft.taskcluster.rootUrl),
publish: cfg.app.publishMetaData,
aws: cfg.aws,
monitor: monitor.prefix('publisher'),
}),
},
Docs can also be generated with exchange.reference()
. See the source code docs for details.
Test Support
For testing, it is useful to be able to verify that messages were sent without
requiring a real AMQP server.
Pass credentials: {fake: true}
to connect
or setup
to get this behavior.
No AMQP connection will be made, but each call to a message-publishing method
will result in a "fakePublish" message emitted from the publisher with content
{exchange, routingKey, payload, CCs}
.
Testing
You'll need to fill a file called user-config.yml
with valid keys. There is a user-config-example.yml
you can copy over to see which keys are needed. Then it is just a matter of yarn install
and yarn test
.
License
Mozilla Public License Version 2.0