RabbitMq部署流程

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
        })
    })
})

你可能感兴趣的:(RabbitMq部署流程)