Merge mqtt backend and plugin #320

Merged
blacklight merged 21 commits from 315/merge-mqtt-backend-and-plugin into master 2023-09-17 02:51:48 +02:00
3 changed files with 25 additions and 26 deletions
Showing only changes of commit b746d0b402 - Show all commits

View File

@ -4,7 +4,7 @@ from .auth import (
authenticate_user_pass,
get_auth_status,
)
from .bus import bus, get_message_response, send_message, send_request
from .bus import bus, send_message, send_request
from .logger import logger
from .routes import (
get_http_port,
@ -25,7 +25,6 @@ __all__ = [
'get_http_port',
'get_ip_or_hostname',
'get_local_base_url',
'get_message_response',
'get_remote_base_url',
'get_routes',
'get_streaming_routes',

View File

@ -1,11 +1,9 @@
from redis import Redis
from platypush.bus.redis import RedisBus
from platypush.config import Config
from platypush.context import get_backend
from platypush.message import Message
from platypush.message.request import Request
from platypush.utils import get_redis_conf, get_redis_queue_name_by_message
from platypush.utils import get_redis_conf, get_message_response
from .logger import logger
@ -67,24 +65,3 @@ def send_request(action, wait_for_response=True, **kwargs):
msg['args'] = kwargs
return send_message(msg, wait_for_response=wait_for_response)
def get_message_response(msg):
"""
Get the response to the given message.
:param msg: The message to get the response for.
:return: The response to the given message.
"""
redis = Redis(**bus().redis_args)
redis_queue = get_redis_queue_name_by_message(msg)
if not redis_queue:
return None
response = redis.blpop(redis_queue, timeout=60)
if response and len(response) > 1:
response = Message.build(response[1])
else:
response = None
return response

View File

@ -662,4 +662,27 @@ def is_root() -> bool:
return os.getuid() == 0
def get_message_response(msg):
"""
Get the response to the given message.
:param msg: The message to get the response for.
:return: The response to the given message.
"""
from platypush.message import Message
redis = get_redis()
redis_queue = get_redis_queue_name_by_message(msg)
if not redis_queue:
return None
response = redis.blpop(redis_queue, timeout=60)
if response and len(response) > 1:
response = Message.build(response[1])
else:
response = None
return response
# vim:sw=4:ts=4:et: