In my GSoC project (more about this here) I need to do a lot of ubus use.
In this case, I want to connect a series of services in a publish-subscribe model.
I want to thank Commodo for his ubus examples… I will be showing a similar example that you can test to have a publish-subscribe pattern implemented in ubus and lua.
In a publish-subscribe you have two type of agents: publishers and subsribers.
Publishers send messages tagged with a specific topic.
Subscribers wait for messages about a specific topic.
Tue Bus is in charge of routing messages based on the topic from publishers to subscribers.
In our case, ubus will act as the Bus.
First, the publisher:
And this is the subscriber:
I still have to figure out how it works… will expand this post once I finish understanding everything.
In particular, I still don’t understand how the notify send an event with a “test.alarm” topic, but the subscribe just listens to “test”… maybe is listening to everything that starts with test.
Nico Echaniz is doing some interesting thing using ubus here:
https://github.com/nicoechaniz/lime-ubus/blob/master/lime_daemon.lua
Instead of doing pubsub he is doing something similar to coroutines.