RabbitMQ使用者在接收MQTT消息时失败

RabbitMQ使用者在接收MQTT消息时失败,rabbitmq,mqtt,pika,Rabbitmq,Mqtt,Pika,我试图通过使用Ubuntu14.04上的RabbitMQ MQTT插件发布MQTT消息,并通过AMQP使用者接收消息。我正在用mosquito客户机包发布MQTT消息。我为RabbitMQ启用了MQTT插件 现在,如果我想发送MQTT消息,我的AMQP使用者代码会抛出一个异常: Traceback (most recent call last): File "consume_topic.py", line 33, in <module> channel.start_consum

我试图通过使用Ubuntu14.04上的RabbitMQ MQTT插件发布MQTT消息,并通过AMQP使用者接收消息。我正在用mosquito客户机包发布MQTT消息。我为RabbitMQ启用了MQTT插件

现在,如果我想发送MQTT消息,我的AMQP使用者代码会抛出一个异常:

Traceback (most recent call last):
   File "consume_topic.py", line 33, in <module>
channel.start_consuming()
   File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 722, in start_consuming
self.connection.process_data_events()
   File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 88, in process_data_events
if self._handle_read():
   File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 184, in _handle_read
super(BlockingConnection, self)._handle_read()
   File "/usr/local/lib/python2.7/dist-packages/pika/adapters/base_connection.py", line 308, in _handle_read
self._on_data_available(data)
   File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 1134, in _on_data_available
consumed_count, frame_value = self._read_frame()
   File "/usr/local/lib/python2.7/dist-packages/pika/connection.py", line 1201, in _read_frame
return frame.decode_frame(self._frame_buffer)
   File "/usr/local/lib/python2.7/dist-packages/pika/frame.py", line 254, in decode_frame
out = properties.decode(frame_data[12:])
   File "/usr/local/lib/python2.7/dist-packages/pika/spec.py", line 2479, in decode
(self.headers, offset) = data.decode_table(encoded, offset)
   File "/usr/local/lib/python2.7/dist-packages/pika/data.py", line 106, in decode_table
value, offset = decode_value(encoded, offset)
   File "/usr/local/lib/python2.7/dist-packages/pika/data.py", line 174, in decode_value
raise exceptions.InvalidFieldTypeException(kind)
pika.exceptions.InvalidFieldTypeException: b
我的RabbitMQ配置文件如下所示:

#!/usr/bin/env python
import pika
import sys

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.exchange_declare(exchange='logs',type='topic',durable=False)

result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue

binding_keys = sys.argv[1:]
if not binding_keys:
    print >> sys.stderr, "Usage: %s [binding_key]..." % (sys.argv[0],)
    sys.exit(1)

for binding_key in binding_keys:
   channel.queue_bind(exchange='logs',
                      queue=queue_name,
                      routing_key=binding_key)

print ' [*] Waiting for logs. To exit press CTRL+C'

def callback(ch, method, properties, body):
    print " [x] %r:%r" % (method.routing_key, body,)

channel.basic_consume(callback,
                      queue=queue_name,
                      no_ack=True)

channel.start_consuming()
[{rabbit,        [{tcp_listeners,    [5672]}]},
 {rabbitmq_mqtt, [{default_user,     <<"guest">>},
                  {default_pass,     <<"guest">>},
                  {allow_anonymous,  true},
                  {vhost,            <<"/">>},
                  {exchange,         <<"logs">>},
                  {subscription_ttl, 1800000},
                  {prefetch,         10},
                  {ssl_listeners,    []},
                  %% Default MQTT with TLS port is 8883
                  %% {ssl_listeners,    [8883]}
                  {tcp_listeners,    [1883]},
                  {tcp_listen_options, [binary,
                                        {packet,    raw},
                                        {reuseaddr, true},
                                        {backlog,   128},
                                        {nodelay,   true}]}]}
].
=INFO REPORT==== 14-Apr-2015::10:57:50 ===
accepting AMQP connection <0.1174.0> (127.0.0.1:42447 -> 127.0.0.1:5672)

=INFO REPORT==== 14-Apr-2015::10:58:30 ===
accepting MQTT connection <0.1232.0> (127.0.0.1:53581 -> 127.0.0.1:1883)

=WARNING REPORT==== 14-Apr-2015::10:58:30 ===
closing AMQP connection <0.1174.0> (127.0.0.1:42447 -> 127.0.0.1:5672):
connection_closed_abruptly

=INFO REPORT==== 14-Apr-2015::10:58:30 ===
closing MQTT connection <0.1232.0> (127.0.0.1:53581 -> 127.0.0.1:1883)
[{rabbit,[{tcp_侦听器,[5672]}],
{rabbitmq_mqtt,[{default_user,},
{default_pass,},
{allow_anonymous,true},
{vhost,},
{exchange,},
{订阅,1800000},
{预取,10},
{ssl_侦听器,[]},
%%带有TLS端口的默认MQTT为8883
%%{ssl_侦听器,[8883]}
{tcp_侦听器,[1883]},
{tcp_listen_options,[binary,
{数据包,原始},
{reuseaddr,true},
{backlog,128},
{nodelay,true}]}
].
日志文件显示以下内容:

#!/usr/bin/env python
import pika
import sys

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
channel = connection.channel()

channel.exchange_declare(exchange='logs',type='topic',durable=False)

result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue

binding_keys = sys.argv[1:]
if not binding_keys:
    print >> sys.stderr, "Usage: %s [binding_key]..." % (sys.argv[0],)
    sys.exit(1)

for binding_key in binding_keys:
   channel.queue_bind(exchange='logs',
                      queue=queue_name,
                      routing_key=binding_key)

print ' [*] Waiting for logs. To exit press CTRL+C'

def callback(ch, method, properties, body):
    print " [x] %r:%r" % (method.routing_key, body,)

channel.basic_consume(callback,
                      queue=queue_name,
                      no_ack=True)

channel.start_consuming()
[{rabbit,        [{tcp_listeners,    [5672]}]},
 {rabbitmq_mqtt, [{default_user,     <<"guest">>},
                  {default_pass,     <<"guest">>},
                  {allow_anonymous,  true},
                  {vhost,            <<"/">>},
                  {exchange,         <<"logs">>},
                  {subscription_ttl, 1800000},
                  {prefetch,         10},
                  {ssl_listeners,    []},
                  %% Default MQTT with TLS port is 8883
                  %% {ssl_listeners,    [8883]}
                  {tcp_listeners,    [1883]},
                  {tcp_listen_options, [binary,
                                        {packet,    raw},
                                        {reuseaddr, true},
                                        {backlog,   128},
                                        {nodelay,   true}]}]}
].
=INFO REPORT==== 14-Apr-2015::10:57:50 ===
accepting AMQP connection <0.1174.0> (127.0.0.1:42447 -> 127.0.0.1:5672)

=INFO REPORT==== 14-Apr-2015::10:58:30 ===
accepting MQTT connection <0.1232.0> (127.0.0.1:53581 -> 127.0.0.1:1883)

=WARNING REPORT==== 14-Apr-2015::10:58:30 ===
closing AMQP connection <0.1174.0> (127.0.0.1:42447 -> 127.0.0.1:5672):
connection_closed_abruptly

=INFO REPORT==== 14-Apr-2015::10:58:30 ===
closing MQTT connection <0.1232.0> (127.0.0.1:53581 -> 127.0.0.1:1883)
=信息报告===2015年4月14日::10:57:50===
接受AMQP连接(127.0.0.1:42447->127.0.0.1:5672)
=信息报告===2015年4月14日::10:58:30===
接受MQTT连接(127.0.0.1:53581->127.0.0.1:1883)
=警告报告===2015年4月14日::10:58:30===
关闭AMQP连接(127.0.0.1:42447->127.0.0.1:5672):
连接突然关闭
=信息报告===2015年4月14日::10:58:30===
关闭MQTT连接(127.0.0.1:53581->127.0.0.1:1883)

谁能帮帮我吗?我在谷歌上搜索了“pika.exceptions.IvalidFieldTypeException”,发现我没有使用正确的“字段类型”,这是怎么回事?

这很可能是pika规范(解码器)中的一个错误。我建议您将库更改为更频繁更新的库。举个例子,你可以看看《皮卡新图书馆》的作者或者我自己的《皮卡灵感图书馆》


尽管如此,也可能是因为您运行的是非常旧的Pika版本。我找到了gmr的commit,它应该可以解决您的问题。您可以尝试升级到。

更新的Pika,现在它工作正常!我仍然在使用旧的Pika版本,因为RabbitMQ教程建议使用Pika v0.9.8,非常感谢!是的,不幸的是,最新的皮卡版本有一些新的问题。其中许多将在0.9.15中修复。