我无法在RabbitMQ上使用MQTT协议

4sup72z8  于 2023-10-20  发布在  RabbitMQ
关注(0)|答案(1)|浏览(116)

我想在我的RabbitMQ代理上使用MQTT协议,但是当我尝试运行我的Producer时,我遇到了一个错误。
这是我的代码。我只是想先测试一下发个信息

import pika
ip = '192.168.43.101'
user = 'ayub'
pasw = 'ayub'
credentials = pika.credentials.PlainCredentials(user,pasw)
connection = pika.BlockingConnection(
    pika.ConnectionParameters(ip, 1883,'/',credentials))
channel = connection.channel()

channel.queue_declare(queue='hello')

def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)
channel.basic_consume(
    queue='hello', on_message_callback=callback, auto_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()

当我运行它。我得到这样的错误

Traceback (most recent call last):
  File "receiver.py", line 8, in <module>
    pika.ConnectionParameters(ip, 1883,'/',credentials))
  File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 359, in __init__
    self._impl = self._create_connection(parameters, _impl_class)
  File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 450, in _create_connection
    raise self._reap_last_connection_workflow_error(error)
pika.adapters.utils.connection_workflow.AMQPConnectorStackTimeout: Timeout during AMQP handshake'192.168.43.101'/(2, 1, 6, '', ('192.168.43.101', 1883)); ssl=False

this my rabbitmqctl状态

Status of node rabbit@raspberrypi ...
[{pid,8288},
 {running_applications,
     [{rabbitmq_management,"RabbitMQ Management Console","3.7.8"},
      {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.7.8"},
      {rabbitmq_management_agent,"RabbitMQ Management Agent","3.7.8"},
      {rabbitmq_mqtt,"RabbitMQ MQTT Adapter","3.7.8"},
      {rabbit,"RabbitMQ","3.7.8"},
      {os_mon,"CPO  CXC 138 46","2.4.7"},
      {cowboy,"Small, fast, modern HTTP server.","2.2.2"},
      {amqp_client,"RabbitMQ AMQP Client","3.7.8"},
      {rabbit_common,
          "Modules shared by rabbitmq-server and rabbitmq-erlang-client",
          "3.7.8"},
      {ranch_proxy_protocol,"Ranch Proxy Protocol Transport","1.5.0"},
      {ranch,"Socket acceptor pool for TCP protocols.","1.5.0"},
      {ssl,"Erlang/OTP SSL application","9.1.2"},
      {public_key,"Public key infrastructure","1.6.4"},
      {asn1,"The Erlang ASN1 compiler version 5.0.8","5.0.8"},
      {jsx,"a streaming, evented json parsing toolkit","2.8.2"},
      {cowlib,"Support library for manipulating Web protocols.","2.1.0"},
      {crypto,"CRYPTO","4.4"},
      {xmerl,"XML parser","1.3.19"},
      {mnesia,"MNESIA  CXC 138 12","4.15.5"},
      {recon,"Diagnostic tools for production use","2.3.2"},
      {inets,"INETS  CXC 138 49","7.0.5"},
      {lager,"Erlang logging framework","3.6.3"},
      {goldrush,"Erlang event stream processor","0.1.9"},
      {compiler,"ERTS  CXC 138 10","7.3.1"},
      {syntax_tools,"Syntax tools","2.1.6"},
      {syslog,"An RFC 3164 and RFC 5424 compliant logging framework.","3.4.3"},
      {sasl,"SASL  CXC 138 11","3.3"},
      {stdlib,"ERTS  CXC 138 10","3.7.1"},
      {kernel,"ERTS  CXC 138 10","6.2"}]},
 {os,{unix,linux}},
 {erlang_version,
     "Erlang/OTP 21 [erts-10.2.4] [source] [smp:4:4] [ds:4:4:10] [async-threads:64]\n"},
 {listeners,
     [{clustering,25672,"::"},
      {amqp,5672,"::"},
      {mqtt,1883,"::"},
      {http,15672,"::"}]},
r1zk6ea1

r1zk6ea11#

Pika是一个AMQP客户端库。您需要使用Python MQTT库,如Eclipse Paho:https://www.eclipse.org/paho/clients/python/docs/

相关问题