RabbitMq部署流程

2019-01-03  本文已影响0人  死鱼

1:下载安装RabbitMq
https://www.rabbitmq.com/install-windows.html (或linux版本)、

2:启动RabbitMq
{RabbitMq location}/sbin/RabbitMq-server.bat

3:生产者程序

const amqp = require("amqplib/callback_api");
amqp.connect("amqp://localhost", function(err, conn){
    conn.createChannel((err, ch)=>{
        var q = "hello";
        ch.assertQueue(q, {
            durable : false
        })
        ch.sendToQueue(q, new Buffer("Hello world"));
        console.log("sended");
    })
})

4:消费者

const amqp = require("amqplib/callback_api");
amqp.connect("amqp://localhost", function(err, conn){
    conn.createChannel((err, ch)=>{
        var q = "hello";
        ch.assertQueue(q, {
            durable : false
        })

        console.log("waitting");

        ch.consume(q, (msg)=>{
            console.log(msg.content.toString());
        }, {
            noAck : true
        })
    })
})
上一篇下一篇

猜你喜欢

热点阅读