美文网首页
RabbitMq部署流程

RabbitMq部署流程

作者: 死鱼 | 来源:发表于2019-01-03 10:41 被阅读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
            })
        })
    })
    

    相关文章

      网友评论

          本文标题:RabbitMq部署流程

          本文链接:https://www.haomeiwen.com/subject/crxfrqtx.html