npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

egg-amqpx

v1.0.4

Published

amqp plugin for egg

Downloads

4

Readme

egg-amqpx

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

Install

$ npm i egg-amqpx --save

Usage

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

Configuration

// {app_root}/config/config.default.js
exports.amqpx = {
  client: {
    url: 'amqp://localhost',
    consumer: {
      // ...
    },
    producer: {
      // ...
    },
  },
};

Queue Mode

定义了一个名为 task 的消息队列

// {app_root}/config/config.default.js
{
  consumer: {
    tasks: {
      mode: 'queue',
      queue: {
        name: 'tasks', // 队列名称
        options: { durable: true },
        prefetch: 1, // 预先取几条消费
        noAck: false
      }
    },
  },
  producer: {
    tasks: {
      mode: 'queue',
      queue: {
        name: 'tasks',
        options: { durable: true }
      }
    },
  }
}
// {app_root}/app/controller/test.js
async test() {
  const message = { queue: 'tasks', content: JSON.stringify({ now: Date.now() }), option: { persistent: true } };
  const result = await this.app.amqpx.send(message); // send to tasks queue
  console.log(`send queue ${result} : ${JSON.stringify(message)}`);
}

PubSub Mode

定义一个发布订阅模式的消费者、生产者

{
  consumer: {
    orders: {
      mode: 'pubsub',
      exchange: {
        name: 'logs', // 交换机名称
        type: 'fanout', // 交换机类型
        options: { durable: false },
      },
      queues: [ // 一个队列对应一个消费者,一个队列可以匹配多条规则
        {
          // name: 'A', // 队列名称
          options: { exclusive: true },
        },
        {
          // name: 'B',
          options: { exclusive: true },
        }
      ]
    }
  },
  producer: {
    orders: {
      mode: 'pubsub',
      exchange: {
        name: 'logs', // 交换机名称
        type: 'fanout', // 交换机类型
        options: { durable: false },
      }
    },
  }
}

Router Mode

{
  consumer: {
    logger: {
      mode: 'router',
      exchange: {
        name: 'logger', // 交换机名称
        type: 'direct', // 交换机类型
        options: { durable: false },
      },
      queues: [ // 一个队列对应一个消费者,一个队列可以匹配多条规则
        {
          // name: 'A', // 队列名称
          router: ['info', 'warning', 'error', 'debug'], // 匹配规则
          options: { exclusive: true },
        },
        {
          // name: 'B',
          router: ['error'],
          options: { exclusive: true },
        }
      ]
    }
  },
  producer: {
    logger: {
      mode: 'router',
      exchange: {
        name: 'logger', // 交换机名称
        type: 'direct', // 交换机类型
        options: { durable: false },
      },
    }
  }
}

Topic Mode

定义按主题模式模式的消费者、生产者

// {app_root}/config/config.default.js
{
  consumer: {
    orders: {
      mode: 'topic',
      exchange: {
        name: 'orders', // 交换机名称,主题 topic
        type: 'topic', // 交换机类型
        options: { durable: false },
      },
      queue: {
        name: 'A', // 队列名称
        subscriber: 'orders', // 消费者名称,对应文件名
        rules: ['files.cn.hz.#'], // 匹配规则
        options: { exclusive: true },
      },
    }
  },
  producer: {
    orders: {
      mode: 'topic',
      exchange: {
        name: 'orders', // 交换机名称,主题 topic
        type: 'topic', // 交换机类型
        options: { durable: false },
      },
    }
  }
}
// {app_root}/app/controller/test.js
const message = {
  exchange: 'orders',
  type: 'topic',
  key: 'files.cn.hz.store',
  content: JSON.stringify({ now: Date.now() }),
};
const result = await this.app.amqpx.publish(message); // send to orders exchange
console.log(`send exchange ${result} : ${JSON.stringify(message)}`);

Example

Questions & Suggestions

Please open an issue here.

License

MIT