UNPKG

hiot-kafka

Version:

hiot-app middleware to bootstrap kafka

40 lines (31 loc) 862 B
"use strict"; const debug = require("debug")("hiot-kafka"); const broker = require("./broker"); module.exports = (options) => { try { const logger = options.logger; options.connectionString = connectionString(options); return (locator) => { debug("register handlers in broker"); options.handlers(broker, locator); debug(`trying to connect to ${options.connectionString}`); return broker.connect(options).then(() => { logger.info(`connected to ${options.connectionString}`); locator.broker = broker; return locator; }); }; } catch (err) { debug(err); } }; function connectionString(options) { var { server, port } = options; if (!server.indexOf(",")) { return `${server}:${port}`; } return server .split(",") .map((s) => `${s}:${port}`) .join(","); }