Make MQTT key configurable #299
This commit is contained in:
parent
ce0d0fb29c
commit
66be351bd3
3 changed files with 6 additions and 4 deletions
|
|
@ -75,6 +75,7 @@ services:
|
||||||
App\Service\MQTTClient:
|
App\Service\MQTTClient:
|
||||||
arguments:
|
arguments:
|
||||||
$redis_client: "@App\\Service\\RedisClientProvider"
|
$redis_client: "@App\\Service\\RedisClientProvider"
|
||||||
|
$key: "mqtt_events"
|
||||||
|
|
||||||
App\Service\APNSClient:
|
App\Service\APNSClient:
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,15 @@ class MQTTClient
|
||||||
{
|
{
|
||||||
const PREFIX = 'motolite.control.';
|
const PREFIX = 'motolite.control.';
|
||||||
const RIDER_PREFIX = 'motorider_';
|
const RIDER_PREFIX = 'motorider_';
|
||||||
const REDIS_KEY = 'events';
|
|
||||||
|
|
||||||
// protected $mclient;
|
// protected $mclient;
|
||||||
protected $redis;
|
protected $redis;
|
||||||
|
protected $key;
|
||||||
|
|
||||||
public function __construct(RedisClientProvider $redis_client)
|
public function __construct(RedisClientProvider $redis_client, $key)
|
||||||
{
|
{
|
||||||
$this->redis = $redis_client->getRedisClient();
|
$this->redis = $redis_client->getRedisClient();
|
||||||
|
$this->key = $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
|
|
@ -29,7 +30,7 @@ class MQTTClient
|
||||||
// $this->mclient->publish($channel, $message);
|
// $this->mclient->publish($channel, $message);
|
||||||
|
|
||||||
$data = $channel . '|' . $message;
|
$data = $channel . '|' . $message;
|
||||||
$this->redis->lpush(self::REDIS_KEY, $data);
|
$this->redis->lpush($this->key, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sendEvent(JobOrder $job_order, $payload)
|
public function sendEvent(JobOrder $job_order, $payload)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ def redis_listen(client, logger):
|
||||||
r = redis.StrictRedis(host='localhost', port=6379, db=0)
|
r = redis.StrictRedis(host='localhost', port=6379, db=0)
|
||||||
while 1:
|
while 1:
|
||||||
time.sleep(0)
|
time.sleep(0)
|
||||||
data = r.brpop("events", 10)
|
data = r.brpop("mqtt_events", 10)
|
||||||
if data:
|
if data:
|
||||||
info = data[1].split('|')
|
info = data[1].split('|')
|
||||||
logger.info("Channel: " + info[0] + " message: " + info[1])
|
logger.info("Channel: " + info[0] + " message: " + info[1])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue