我无法在RabbitMQ上使用MQTT协议

问题描述 投票:0回答:1

我想在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

这是我的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,"::"}]},
rabbitmq mqtt pika
1个回答
0
投票

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


[NOTE: RabbitMQ团队监视rabbitmq-users mailing list,并且有时仅在StackOverflow上回答问题。

© www.soinside.com 2019 - 2024. All rights reserved.