Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no message in subscriber #212

Open
Nehru-Wairokpam opened this issue Apr 1, 2020 · 8 comments
Open

no message in subscriber #212

Nehru-Wairokpam opened this issue Apr 1, 2020 · 8 comments

Comments

@Nehru-Wairokpam
Copy link

No description provided.

@Nehru-Wairokpam
Copy link
Author

pliz solved this bugs

@Nehru-Wairokpam
Copy link
Author

import logging
import asyncio
from hbmqtt.broker import Broker
from hbmqtt.client import MQTTClient, ClientException
from hbmqtt.mqtt.constants import QOS_1,QOS_2

import paho.mqtt.client as mqtt

client = mqtt.Client()

logger = logging.getLogger(name)

config = {
'listeners': {
'default': {
'type': 'tcp',
'bind': '127.0.0.1:1888' # 0.0.0.0:1883
}
},
'auth':{
'allow-anonymous': True
},
'sys_interval': 10,
'topic-check': {
'enabled': False
}
}

broker = Broker(config)

@asyncio.coroutine
def startBroker():
yield from broker.start()

async def uptime_coro():
C = MQTTClient()
await C.connect('mqtt://127.0.0.1:1888/')
await C.subscribe([('Nehru/test', QOS_1)])
try:
while 1:
message = await C.deliver_message()
packet = message.publish_packet
#proc_to_arctic(packet.variable_header.topic_name, packet.payload.data.decode('utf8'))
print(packet.variable_header.topic_name, packet.payload.data.decode('utf8'))

        await C.unsubscribe([TOPIC])
        await C.disconnect()

    except ClientException as ce:
        logger.error("Client exception: %s" % ce)

if name == 'main':
formatter = "[%(asctime)s] :: %(levelname)s :: %(name)s :: %(message)s"
logging.basicConfig(level=logging.INFO, format=formatter)
asyncio.get_event_loop().run_until_complete(startBroker())
asyncio.get_event_loop().run_until_complete(uptime_coro())
asyncio.get_event_loop().run_forever()

@lanhaosmile
Copy link

I'm not sure if it is the issue description.
While starting the broker with config of topic_check disabled and without any check plugins, the add_subscription function @broker.py line 613 thrown the exception KeyError. No message in subcriber since subcription faild to be added.

The KeyError might be caused by None value of topic_plugins at the following lines @ broker.py.
line 583
returns = yield from self.plugins_manager.map_plugin_coro( "topic_filtering", session=session, topic=topic, filter_plugins=topic_plugins)

@ShenTengTu
Copy link

I have same problem for with topic_check disabled.

There is stacktrace as below if removing try-catch in add_subscription() @broker.py:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/websockets/server.py", line 191, in handler
    await self.ws_handler(self, path)
  File "/home/pi/projects/CONTRIBUTING/hbmqtt/hbmqtt/broker.py", line 340, in ws_connected
    yield from self.client_connected(listener_name, WebSocketsReader(websocket), WebSocketsWriter(websocket))
  File "/home/pi/projects/CONTRIBUTING/hbmqtt/hbmqtt/broker.py", line 470, in client_connected
    result = yield from self.add_subscription(subscription, client_session)
  File "/home/pi/projects/CONTRIBUTING/hbmqtt/hbmqtt/broker.py", line 626, in add_subscription
    permitted = yield from self.topic_filtering(session, topic=a_filter)
  File "/home/pi/projects/CONTRIBUTING/hbmqtt/hbmqtt/broker.py", line 588, in topic_filtering
    filter_plugins=topic_plugins)
  File "/home/pi/projects/CONTRIBUTING/hbmqtt/hbmqtt/plugins/manager.py", line 209, in map_plugin_coro
    return (yield from self.map(self._call_coro, coro_name, *args, **kwargs))
  File "/home/pi/projects/CONTRIBUTING/hbmqtt/hbmqtt/plugins/manager.py", line 183, in map
    ret_list = yield from asyncio.gather(*tasks, loop=self._loop)
  File "/home/pi/projects/CONTRIBUTING/hbmqtt/hbmqtt/plugins/manager.py", line 195, in _call_coro
    return (yield from coro)
  File "/usr/lib/python3.7/asyncio/coroutines.py", line 120, in coro
    res = func(*args, **kw)
  File "/home/pi/projects/CONTRIBUTING/hbmqtt/hbmqtt/plugins/topic_checking.py", line 75, in topic_filtering
    allowed_topics = self.topic_config['acl'].get(username, None)
KeyError: 'acl'

topic_filtering() @broker.py still invoke topic_checking plugin if topic-check disabled, because topic_filtering() only keeps the keyword argument filter_plugins as None.

And in the topic_checking plugin, it doesn't check whether topic filtering is disabled.

@ShenTengTu
Copy link

The current solution is to add the acl field to the configuration.

broker.yaml
# ...
topic-check:
  enabled: False
  acl:
    anonymous: ["the_topic/#", "..."]
    user_name: ["another_topic/#", "..."]
# ...

@Nolven
Copy link

Nolven commented Mar 19, 2021

Same here, spend a whole hecking day trying to make this, ehhhh, thing, work, but found no better solution than settin' ac1

@FlorianLudwig
Copy link
Contributor

This might be related to this issue here: Yakifo/amqtt#28

@Jaasdsa
Copy link

Jaasdsa commented Apr 7, 2021

this is keng!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants