exchange_declare() got an unexpected keyword argument 'type'

在用rabbitmq调试生产者消费者demo时,报错如题目所示

Traceback (most recent call last):
  File "testConn.py", line 7, in 
    channel.exchange_declare(exchange="hello-exchange", type="direct", passive=False, durable=True, auto_delete=False)
TypeError: exchange_declare() got an unexpected keyword argument 'type'

查看源码

import pika, sys

credentials = pika.PlainCredentials("guest", "guest")
conn_params = pika.ConnectionParameters("localhost", credentials = credentials)
conn_broker = pika.BlockingConnection(conn_params)
channel = conn_broker.channel()
channel.exchange_declare(exchange="hello-exchange", type="direct", passive=False, durable=True, auto_delete=False)

msg = sys.argv[1]
msg_props = pika.BasicProperties()
msg_props.content_type = "text/plain"
channel.basic_publish(body=msg, exchange="hello-exchange", properties=msg_props, routing_key="hola")

因为api做了调整,将修改type为exchange_type即可正常运行。

你可能感兴趣的:(rabbitmq)