node js -- 使用 amqplib模块

var rabbitmq= {
        hostname:"192.1",
	port:"5672",
	username:"dep",
	password:"devl8",
	authMechanism: "AMQPLAIN" ,
	pathname:"/",
	ssl: { 
		enabled : false  
    }  
}


var open = require('amqplib').connect(rabbitmq).then(function(conn){
		  conn.createChannel().then((ch)=>{       //创建通道
			
			ch.assertExchange('api', 'topic',{durable:true}).then(function(ex) {    //连接交换机
					
					ch.assertQueue("topic").then(function(q) {     //连接队列
                                                             //队列     交换机     Rounting KEY   arguments
						 ch.bindQueue(q.queue,ex.exchange,"topic",{'x-match': 'any',
						 'foo': 'bar',
						 'baz': 'boo'})      //交换机bind队列
						                               //Routing key
						var a =ch.publish(ex.exchange, 'topic', new Buffer(JSON.stringify({name:"chendong"})), {headers: {baz: 'boo'}})
					     if(a){
							console.log("发送成功")
						//  conn.close()
						 }else{
							console.log("发送失败");
						//  conn.close()
						 }

						
					});
				});
		  })




},console.error)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值