python-3.x - How to set connection friendly name RabbitMQ --Python
问题描述
Hello i am playing around with RabbitMq and i have a question. I have many parallel nodes running and are connected on rabbitmq-server. The thing is that in conncetions are stated like ip:port
Also under ip:port
there is a ?
. Is there a way to set up a friendly name for python 3.6 ?
P.S I have tried something like this without success
parameters = pika.ConnectionParameters(
host='localhost',
virtual_host='/',
client_properties={
'connection_name': 'random name',
},
)
connection = pika.BlockingConnection(parameters)
P.S Also i found a related question about golang tho. Here How to set connection friendly name
Versions
pika = '1.1.0'
RabbitMq = '3.8.0'
Erlang = '22.1.1'
Python = ' 3.6.8'
Any ideas? :)
解决方案
此代码设置连接名称,如您在此处看到的:
import functools
import logging
import pika
LOG_FORMAT = ('%(levelname) -10s %(asctime)s %(name) -30s %(funcName) '
'-35s %(lineno) -5d: %(message)s')
LOGGER = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
def on_message(chan, method_frame, _header_frame, body, userdata=None):
"""Called when a message is received. Log message and ack it."""
LOGGER.info('Userdata: %s Message body: %s', userdata, body)
chan.basic_ack(delivery_tag=method_frame.delivery_tag)
def main():
"""Main method."""
credentials = pika.PlainCredentials('guest', 'guest')
props = { 'connection_name' : 'https://stackoverflow.com/q/58275505/1466825' }
parameters = pika.ConnectionParameters('localhost', credentials=credentials, client_properties=props)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.exchange_declare(
exchange='test_exchange',
exchange_type='direct',
passive=False,
durable=True,
auto_delete=False)
channel.queue_declare(queue='standard', auto_delete=True)
channel.queue_bind(
queue='standard', exchange='test_exchange', routing_key='standard_key')
channel.basic_qos(prefetch_count=1)
on_message_callback = functools.partial(
on_message, userdata='on_message_userdata')
channel.basic_consume('standard', on_message_callback)
try:
channel.start_consuming()
except KeyboardInterrupt:
channel.stop_consuming()
connection.close()
if __name__ == '__main__':
main()
注意: RabbitMQ 团队会监控rabbitmq-users
邮件列表,有时只会在 StackOverflow 上回答问题。
推荐阅读
- javascript - 服务器发送的事件在某个服务器上不起作用
- python - Selenium Headless chrome 运行速度要慢得多
- python - Git:如何保存并返回到特定版本
- swiftui - @State 和 CoreData 的 SwiftUI 预览问题
- python - 从两个 CSV 文件中读取
- java - 必需的列表参数“ids”不存在
- linux - 可以在 Linux 机器上安装 Payara 服务器多个版本
- python-3.x - /users/signup/“password_1”处的 MultiValueDictKeyError
- c - cs50 PSET4的模糊功能,错误在哪里?
- c - 在子线程中终止使用 system() 启动的程序