New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

egg-pulsar

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-pulsar

pulsar plugin for egg

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

egg-pulsar

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Apache pulsar plugin for egg

中文文档

Install

// https://pulsar.apache.org/docs/en/client-libraries-cpp/

// install pulsar-client-dev lib for macOS
$ brew install libpulsar

$ npm i egg-pulsar --save

Usage

// {app_root}/config/plugin.js
exports.pulsar = {
  enable: true,
  package: 'egg-pulsar',
};

Configuration

// {app_root}/config/config.default.js
exports.pulsar = {
  client: {
    url: 'pulsar://localhost:6650',
    options: {
      operationTimeoutSeconds: 30,
    },
    subscribe: {
      topic: 'persistent://public/default/my-topic',
      subscription: 'sub1',
      subscriptionType: 'Shared',
      ackTimeoutMs: 10000,
      listener: 'xxx', // 对应 app/subscriber/xxx
    },
  }
};

see apache pulsar client-libraries-node for more detail.

Example

Producer Send Message

// {app_root}/app/controller/home.js
'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;

    await this.app.pulsar.send({ now: Date.now() }, 'my-topic');
    // or
    await this.app.pulsar.send({ now: Date.now() }, { topic: 'my-topic' });
    // or
    await this.app.pulsar.send({ data: { now: Date.now() }, properties: [ 'a', 'c' ] }, { topic: 'my-topic' });

    ctx.body = 'hi, egg';
  }
}

module.exports = HomeController;

Consumer Message Of Subscriber

// {app_root}/app/subscriber/test.js
'use strict';

const debug = require('debug')('subscriber');

class TestSubscriber {
  constructor(ctx) {
    this.ctx = ctx;
    this.app = ctx.app;
  }

  async consume(message) {
    debug('message: %s', JSON.stringify(message));
    console.log(message);
    // throw ('consume message error');
  }
}

module.exports = TestSubscriber;

Test

// pulsar server run on docker 
$ docker run -it \
-p 6650:6650 \
-p 8080:8080 \
--mount source=pulsardata,target=/pulsar/data \
--mount source=pulsarconf,target=/pulsar/conf \
apachepulsar/pulsar:2.7.2 \
bin/pulsar standalone

Questions & Suggestions

Please open an issue here.

License

MIT

Keywords

pulsar

FAQs

Package last updated on 02 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts