EMQ X extension Python SDK
Using Python to handle the hooks in EMQ X to record connection and disconnection information, realize client authentication, ACL check and message storage.
Install
EMQ X extension requires Python 3.6 or later :
pip3 install emqx-extension-sdk
The emqx-extension-sdk is open source, welcome to commit to help us improve the function.
Download
You can use the open source version for most functions, but only EMQ X Enterprise edition supports message storage.
Download EMQ X MQTT Broker v4.1 +
EMQ X Enterprise v4.1 is coming.
Configuration
Use emqx-extension-hook plugins:
## Setup the supported drivers
##
## Value: python2 | python3 | java
exhook.drivers = python3
## Search path for scripts/library
exhook.drivers.python3.path = data/extension/hooks.py
## Call timeout
##
## Value: Duration
##exhook.drivers.python3.call_timeout = 5s
## Initial module name
## Your filename or module name
exhook.drivers.python3.init_module = hooks
example:
## data/extension/hooks.py
from emqx_extension.hooks import EmqxHookSdk, hooks_handler
from emqx_extension.types import EMQX_CLIENTINFO_PARSE_T, EMQX_MESSAGE_PARSE_T
class CustomHook(EmqxHookSdk):
@hooks_handler()
def on_client_connect(self,
conninfo: EMQX_CLIENTINFO_PARSE_T = None,
props: dict = None,
state: list = None):
print(f'[Python SDK] [on_client_connect] {conninfo.clientid} connecte')
@hooks_handler()
def on_client_connected(self,
clientinfo: EMQX_CLIENTINFO_PARSE_T,
state: list = None):
print(
f'[Python SDK] [on_client_connected] {clientinfo.clientid} connected')
@hooks_handler()
def on_client_check_acl(self, clientinfo: EMQX_CLIENTINFO_PARSE_T,
pubsub: str,
topic: str,
result: bool,
state: tuple) -> bool:
print(
f'[Python SDK] [on_client_check_acl] {clientinfo.username} check ACL: {pubsub} {topic}')
if clientinfo.username == '':
return False
return True
@hooks_handler()
def on_client_authenticate(self, clientinfo: EMQX_CLIENTINFO_PARSE_T, authresult,
state) -> bool:
print(
f'[Python SDK] [on_client_authenticate] {clientinfo.clientid} authenticate')
if clientinfo.clientid != '':
return True
return False
# on_message_* only EMQ X Enterprise
@hooks_handler()
def on_message_publish(self, message: EMQX_MESSAGE_PARSE_T, state):
print(
f'[Python SDK] [on_message_publish] {message.topic} {message.payload}')
emqx_hook = CustomHook(hook_module=f'{__name__}.emqx_hook')
def init():
return emqx_hook.start()
def deinit():
return
Benchmark
Coming soon.
Load plugin
./bin/emqx_ctl plugins load emqx_extension_hook
Metadata
Release files for emqx-extension-sdk 0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| emqx-extension-sdk-0.2.tar.gz | 4.1 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| emqx_extension_sdk-0.2-py3.6.egg | Legacy Egg format | - | - | Details |
| emqx_extension_sdk-0.2-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 22.1 kB
Release files / emqx-extension-sdk-0.2.tar.gz
| Download URL | emqx-extension-sdk-0.2.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f11b0c6d923fd7adc5bbf89571ff302286093840df009496b552b1479686336
|
|
BLAKE2b-256 checksum How to use checksums |
2eb4621bf740b5a66b59677adea6b86ed797c70541c4b74ce0c8dcf0783f8979
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.7
|
Release files / emqx_extension_sdk-0.2-py3.6.egg
| Download URL | emqx_extension_sdk-0.2-py3.6.egg |
|---|---|
| Size | 9.0 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
5dbcf0957fa0bee417e38fa16205b8a5ce6c5ec46c5687352fb6da1e7ab0b309
|
|
BLAKE2b-256 checksum How to use checksums |
d29cee3a40eb2c20ea137fe70b1c8b50094137b19810cc63f3b6dba875646421
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.7
|
Release files / emqx_extension_sdk-0.2-py2-none-any.whl
| Download URL | emqx_extension_sdk-0.2-py2-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
e433910ac3ebaa7c3db549ffa05ac208377b33d9c7ce155f542efa79f21c2980
|
|
BLAKE2b-256 checksum How to use checksums |
9ef76b2fa590c20ebf674483d5314d0f9f30d5f157a88c848f38e30ad1307804
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.7
|