Comments (6)
Here's my code which produced the error message:
subscriber.py
# MQTTv5 client
import asyncio
from gmqtt import Client as MQTTClient
import time
import signal
STOP = asyncio.Event()
def ask_exit(*args):
STOP.set()
# Handle incoming MQTT messages
def handle_mqtt_message(client, topic, payload, qos, properties):
print("Received message '" + str(payload.decode()) + "' on topic '" + topic + "'.")
# Set up MQTTv5 client
async def main():
client = MQTTClient("subscriber", topic_alias_maximum=10)
client.on_message = handle_mqtt_message
await client.connect('127.0.0.1')
client.subscribe('test')
await STOP.wait()
await client.disconnect()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.add_signal_handler(signal.SIGINT, ask_exit)
loop.add_signal_handler(signal.SIGTERM, ask_exit)
loop.run_until_complete(main())
publisher.py:
# MQTTv5 client
import asyncio
from gmqtt import Client as MQTTClient
import time
import signal
client = None
STOP = asyncio.Event()
def ask_exit(*args):
STOP.set()
async def publish():
global client
alias_set = False
for _ in range(0, 2):
await asyncio.sleep(1)
client.publish('' if alias_set else 'test', str(time.time()), topic_alias=1)
if not alias_set:
alias_set = True
# Set up MQTTv5 client
async def main():
global client
client = MQTTClient("publisher", topic_alias_maximum=10)
await client.connect('127.0.0.1')
asyncio.ensure_future(publish())
await STOP.wait()
await client.disconnect()
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.add_signal_handler(signal.SIGINT, ask_exit)
loop.add_signal_handler(signal.SIGTERM, ask_exit)
loop.run_until_complete(main())
from gmqtt.
Hi @pablogamboa
Thanks, happy to hear this!
Actually there is topic alias support, like any others properties. But you should manage yourself set of topic aliases you use.
So here is quick example:
pub_client.publish('TEST/PROPS/42', '42 is the answer', qos=1, content_type='utf-8',
message_expiry_interval=60, topic_alias=42, user_property=('time', str(time.time())))
pub_client.publish('', '42 is still the answer', qos=1, content_type='utf-8',
message_expiry_interval=60, topic_alias=42, user_property=('time', str(time.time())))
First client publishes messages with topic string and kwarg topic_alias=int
. After this initial message client can publish message with empty string topic and same topic_alias
kwarg.
Sure, you can send a PR with example of how you use topic aliases or any extended support of topic aliases management.
from gmqtt.
Hi @Lenka42 thanks for the fast reply. Awesome to hear that's supported! At least this question will serve as documentation, but for sure we could add a wee section in the docs around it. It's a great MQTT5 addition and I'm sure other users will wonder about it. Closing the issue, thanks again!
from gmqtt.
gmqtt seems to not work with brokers that use topic aliases on outgoing PUBLISHs.
I have tried to use gmqtt with the Paho testing broker (https://github.com/eclipse/paho.mqtt.testing) which does this. When the PUBLISH packets with empty topic and topic alias property reach the client, it logs an error message:
[MQTT ERR PROTO] topic name is empty
A PUBLISH with non-empty topic and topic alias property was sent before this.
In my quick check of the code I did not find any handling of incoming topic aliases (setting up a mapping). Do you plan to add support for this?
from gmqtt.
Hi @veracl, thanks for your notice. You are right, at this moment gmqtt didn't support if SERVER (broker) send an PUBLISH package without topic. You will help us if send a little snippet of your code, which reproducing this error;
We will fix this in the next version (0.6.7)
from gmqtt.
Hi, @veracl
Thanks for your code snippet it helped us to test and release this feature faster. Please checkout our new version of gmqtt 0.6.7;
from gmqtt.
Related Issues (20)
- Develop my own fault recovery logic using gmqtt client
- GMQTT with TLS: Not able to connect to broker #122 HOT 15
- How to increase the max in IdGenerator from client? HOT 1
- Resubscribe after autoreconnect HOT 1
- [PROPERTIES] received invalid property id 105, disconnecting HOT 2
- Handler does not work for null body retained messages published before the handler created HOT 6
- Client still running after disconnect() in 0.6.9 HOT 1
- Exceeded reconnect_retries seems seems not to be working HOT 1
- Unsubscribe doesn't remove the topic from the internal list
- I can't to use ca.crt, client.crt, client.key (X509 certificate) to connect mqtt broker. HOT 2
- Read message from mqtt and post Data to wialon HOT 1
- request and response mechanism
- won't remove resend messages if PUBREC is faster than message pushed HOT 1
- publish() and then disconnect() may result in messages not received by a broker
- is there a handler like python.paho.mqtt message_callback_add? HOT 2
- No PubBack Message HOT 1
- Connection error
- [RECV EMPTY] Connection will be reset automatically. HOT 1
- blocking the loop when processing messages for a long time HOT 1
- Formal documentation for API HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gmqtt.