RabbitMQ_direct
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@version:
@author: morgana
@license: Apache Licence
@contact: vipmorgana@gmail.com
@site:
@software: PyCharm
@file: myproductor_director.py
@time: 2018/4/15 上午12:24
"""
import pika
import sys credentials = pika.PlainCredentials('morgana', '123456') parameters = pika.ConnectionParameters(host='127.0.0.1',credentials=credentials)
connection = pika.BlockingConnection(parameters) channel = connection.channel() #队列连接通道 channel.exchange_declare(exchange='direct_log',exchange_type='direct') log_level = sys.argv[1] if len(sys.argv) > 1 else 'info' message = ' '.join(sys.argv[1:]) or "info: Hello World!" channel.basic_publish(exchange='direct_log',
routing_key=log_level,
body=message)
print(" [x] Sent %r" % message)
connection.close()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@version:
@author: morgana
@license: Apache Licence
@contact: vipmorgana@gmail.com
@site:
@software: PyCharm
@file: mycustomer_director.py
@time: 2018/4/15 上午12:25
"""
__author__ = 'Administrator'
import pika,sys
import pika
import sys credentials = pika.PlainCredentials('morgana', '123456') parameters = pika.ConnectionParameters(host='127.0.0.1',credentials=credentials)
connection = pika.BlockingConnection(parameters) channel = connection.channel() #队列连接通道 queue_obj = channel.queue_declare(exclusive=True) #不指定queue名字,rabbit会随机分配一个名字,exclusive=True会在使用此queue的消费者断开后,自动将queue删除
queue_name = queue_obj.method.queue
print('queue name',queue_name,queue_obj) log_levels = sys.argv[1:] # info warning errr if not log_levels:
sys.stderr.write("Usage: %s [info] [warning] [error]\n" % sys.argv[0])
sys.exit(1) for level in log_levels:
channel.queue_bind(exchange='direct_log',
queue=queue_name,
routing_key=level) #绑定队列到Exchange print(' [*] Waiting for logs. To exit press CTRL+C') def callback(ch, method, properties, body):
print(" [x] %r" % body) channel.basic_consume(callback,queue=queue_name, no_ack=True) channel.start_consuming()
RabbitMQ_direct的更多相关文章
随机推荐
- LARAVEL IOC容器 示例解析
<?php class People { public $dog = null; public function __construct() { $this->dog = new Dog( ...
- Windows批处理笔记
1. 路径类相关代号 %i提取第i个命令选项,例如%1提取第1个option,i可以取值从1到9 %~0: 取文件名(名+扩展名) %~f0:取全路径 %~d0:取驱动器名 %~p0:只取路径(不包驱 ...
- Encode Adjacent Letters
Encode a string by counting the consecutive letter. (i.e., "aaaabbxxxyyz" might become &qu ...
- vps上搭建jupyter notebook远程服务
安装anaconda 使用如下命令下载: wget https://repo.continuum.io/archive/Anaconda3-5.0.0.1-Linux-x86_64.sh 如果非roo ...
- ss client 配置
1.1安装ss apt-get install python-pippip install shadowsocks 1.2配置ss 新建一个配置文件config.json/etc/shadowsock ...
- 使用 GitVersion 在编译或持续构建时自动使用语义版本号(Semantic Versioning)
我们在之前谈过 语义版本号(Semantic Versioning),在项目中应用语义版本号能够帮助库的开发者在发布包时表明更多的语义信息.这是趋势,从微软的博客 Versioning NuGet p ...
- .NET类库
1.如何让发布的C#的DLL类库中的方法带有注释说明 一个类库让第三方引用时,默认情况下生成类库时不携带注释,所以别人引用这个类库时就不是很方便理解类方法的作用和每个参数的含义,若是能携带方法的说明注 ...
- ballerina 学习七 object 创建&& 初始化
在 ballerina 总中object 是一个包含public private 类型字段同时包含函数,需要开发人员进行自定义类型以及行为 说白了,就是类似面向对象的class 基本使用 代码 imp ...
- grpc gateway 使用以及docker compose 集成
1. grpc gateway 安装 参考,比较简单,有需要的依赖可以参考相资料 mkdir tmp cd tmp git clone https://github.com/google/protob ...
- openresty luarocks 安装以及openssl 问题处理
1. 安装方式 wget https://luarocks.github.io/luarocks/releases/luarocks-2.4.3.tar.gz tar -xzvf luarocks ...