2020-07-23 15:19:35 +02:00
|
|
|
|
# System / `psmq` Publish Subscribe Message Queue
|
2019-02-19 00:51:50 +01:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
`psmq` is publish subscribe message queue. It's a set of programs and libraries
|
|
|
|
|
to implement publish/subscribe way of inter-process communication on top of
|
2019-02-19 00:51:50 +01:00
|
|
|
|
POSIX message queue.
|
|
|
|
|
|
2021-05-23 22:36:32 +02:00
|
|
|
|
Manuals, source code and more info at: https://psmq.bofc.pl
|
2019-02-19 00:51:50 +01:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
Little demo using `psmqd` broker, `psmq_pub` and `psmq_sub`:
|
2019-02-19 00:51:50 +01:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
Start broker and make it log to file
|
2019-02-19 00:51:50 +01:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
2021-05-23 22:36:32 +02:00
|
|
|
|
nsh> psmqd -b/brok -p/sd/psmqd/psmqd.log &
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
2019-02-19 00:51:50 +01:00
|
|
|
|
|
2021-05-23 22:36:32 +02:00
|
|
|
|
Start subscribe thread that will read all messages send on `/can/*` and
|
|
|
|
|
`/adc/*` topic, and dump all readings to file
|
2019-02-19 00:51:50 +01:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
2021-05-23 22:36:32 +02:00
|
|
|
|
nsh> psmq_sub -n/sub -b/brok -t/can/* -t/adc/* -o/sd/psmq-sub/can.log &
|
2020-07-23 15:19:35 +02:00
|
|
|
|
n/connected to broker /brok
|
2021-05-23 22:36:32 +02:00
|
|
|
|
n/subscribed to: /can/*
|
|
|
|
|
n/subscribed to: /adc/*
|
2020-07-23 15:19:35 +02:00
|
|
|
|
n/start receiving data
|
2021-05-23 22:36:32 +02:00
|
|
|
|
n/reply timeout set 100
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
2019-02-19 00:51:50 +01:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
Publish some messages
|
2019-02-19 00:51:50 +01:00
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
nsh> psmq_pub -b/brok -t/can/engine/rpm -m50
|
|
|
|
|
nsh> psmq_pub -b/brok -t/adc/volt -m30
|
|
|
|
|
nsh> psmq_pub -b/brok -t/can/room/10/temp -m23
|
|
|
|
|
nsh> psmq_pub -b/brok -t/pwm/fan1/speed -m300
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Check out subscribe thread logs
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
nsh> cat /sd/psmq-sub/can.log
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```
|
2021-05-23 22:36:32 +02:00
|
|
|
|
[2021-05-23 17:53:59] p:0 l: 3 /can/engine/rpm 50
|
|
|
|
|
[2021-05-23 17:53:59] p:0 l: 3 /adc/volt 30
|
|
|
|
|
[2021-05-23 17:53:59] p:0 l: 3 /can/room/10/temp 23
|
2020-07-23 15:19:35 +02:00
|
|
|
|
```
|
|
|
|
|
|
2021-05-23 22:36:32 +02:00
|
|
|
|
As you can see `/pwm/fan1/speed` hasn't been received by subscribe thread,
|
|
|
|
|
since we didn't subscribe to it.
|
2019-02-19 00:51:50 +01:00
|
|
|
|
|
|
|
|
|
Content:
|
|
|
|
|
|
2020-07-23 15:19:35 +02:00
|
|
|
|
- `psmqd` – broker, relays messages between clients.
|
|
|
|
|
- `psmq_sub` – listens to specified topics, can be used as logger for
|
|
|
|
|
communication (optional).
|
|
|
|
|
- `psmq_pub` – publishes messages directly from shell. Can send binary data, but
|
2019-02-19 00:51:50 +01:00
|
|
|
|
requires pipes, so on nuttx it can only send ASCII.
|
2020-07-23 15:19:35 +02:00
|
|
|
|
- `libpsmq` – library used to communicate with the broker and send/receive
|
|
|
|
|
messages.
|