DPIclimate / broker

3 stars 3 forks source link

Create a delivery service base class #93

Closed dajtxx closed 1 month ago

dajtxx commented 1 month ago

Delivery services should all have similar logic so it might be worth creating a base class they can derive from what does all the work of setting up the RabbitMQ infra and leaves the delivery service itself to just process messages.

If using RabbitMQ exchanges and queues:

How to read the DLEX occasionally, rather than all the time? Like once an hour or so.

dajtxx commented 1 month ago

See also issue #36 .

This issue is using the DLEX rather than a db table as a store for undelivered messages, and still tries to deliver the message before putting it in the store.

36 suggests storing the message first and delivering later. That idea is possibly more difficult in a single process, requiring async code (with luck a thead could be used instead?) but does seem cleaner. The table or DLEX can be read through from start to finish with messages removed as they are successfully delivered, and then the cycle just starts again until the table is empty. The timing of final message delivery is also now independent of arrival for situations where there is a rate limit, such as Ubidots, so reception isn't held up by delivery rates.

If the async/threaded code can be hidden in the base class then the subclasses are still simple.

dajtxx commented 1 month ago

Base class is working, uses the db table idea from #36.

The db table could be more efficient if it stored the uid from the physical_devices table and then the message could be retrieved from there. This means the uid needs to be passed from the logical mapper onwards, either added to the message or replacing the message in the logical_timeseries exchange messages. Replacing means all delivery processes would need to use the new mechanism, whereas including the uid in the JSON message means delivery processes could pick it out and store it in their table.

dajtxx commented 1 month ago

Implemented in 35c1c38.

Note it is still worth considering just passing a message id into the logical_timeseries exchange now and having delivery services read from the physical_timeseries table. But that can wait for another time.