Git Product home page Git Product logo

mq8's Introduction

mq8

  • 一个简单的amqplib封装

usage

安装

$ npm i https://github.com/cbdyzj/mq8.git 

使用

import { Queue, Exchange, debug, sleep } from 'mq8'

// 消息消费者
async function consumer() {
    const queue = new Queue({ name: 'test' })
    queue.setConsumer(msg => {
        debug('收到消息:', msg.content.toString())
        queue.ack(msg)
    })
}

// 消息生产者1
async function producer1() {
    const queue = new Queue({ name: 'test' })
    while (true) {
        await queue.sendToQueue(Buffer.from('1: ' + (new Date).toLocaleTimeString()))
        await sleep(1000)
    }
}

// 消息生产者2
async function producer2() {
    const exchange = new Exchange({ name: 'test' })
    await sleep(500)
    while (true) {
        await exchange.publish('test', Buffer.from('2: ' + (new Date).toLocaleTimeString()))
        await sleep(1000)
    }
}

consumer()
producer1()
producer2()

rabbitmq

$ docker-compose up -d
$ npm test

mq8's People

Contributors

cbdyzj avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

786493045

mq8's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.