Windshaft-cartodb/lib/backends/pubsub-metrics.js
2020-04-27 13:27:05 +02:00

18 lines
494 B
JavaScript

'use strict';
const { PubSub } = require('@google-cloud/pubsub');
module.exports = class PubSubMetricsBackend {
constructor (options = {}) {
const { project_id: projectId, credentials: keyFilename, topic } = options;
this._pubsub = new PubSub({ projectId, keyFilename });
this._topicName = topic;
}
send (event, attributes) {
const data = Buffer.from(event);
return this._pubsub.topic(this._topicName).publish(data, attributes);
}
};