Event Subsystem¶
The event subsystem provides a mechanism that allows 3rd parties to remain well informed about the state of the system without having to poll it.
It is entirely optional, the system should work in a “fire and forget” manner. This means that the B2G interactions do not require further action on behalf of the Business. However, because the system operates with eventual consistency and best effort semantics (i.e. not guaranteed delivery semantics) the event subststem may help applications orchestrate their distributed processes.
Subscriptions API¶
This is basically an implementation of WebSub https://en.wikipedia.org/wiki/WebSub. It allows Message API clients to discover (be notified of) message changes without polling.
The implementation is /intergov/apis/subscriptions_api
The business logic is in these classes:
SubscriptionDeregistrationUseCase (in /intergov/use_cases/subscription_deregister.py)
SubscriptionRegisterUseCase (in /intergov/use_cases/subscription_register.py)
Callbacks Spreader¶
This is part of the WebSub infrastructure that processes each event once.
-
class
intergov.processors.callbacks_spreader.
CallbacksSpreaderProcessor
(notifications_repo_conf=None, delivery_outbox_repo_conf=None, subscriptions_repo_conf=None)[source]¶ Convert each incoming message to set of messages containing (websub_url, message) so they may be sent and fail separately
-
class
intergov.use_cases.dispatch_message_to_subscribers.
DispatchMessageToSubscribersUseCase
(notifications_repo, delivery_outbox_repo, subscriptions_repo)[source]¶ Used by the callbacks spreader worker.
This is the “fan-out” part of the WebSub, where each event dispatched to all the relevant subscribers. For each event (notification), it looks-up the relevant subscribers and dispatches a callback task so that they will be notified.
There is a downstream delivery processor that actually makes the callback, it is insulated from this process by the delivery outbox message queue.
Note: In this application the subscription signature is based on the message predicate.
Callback Deliver¶
This is the part of the WebSub infrastructure that processes each message once for every relevant subscriber. It deffers to an external message queue to implement best-effort delivery semantics.
-
class
intergov.processors.callback_deliver.
CallbacksDeliveryProcessor
(delivery_outbox_repo_conf=None)[source]¶ Iterate over the DeliverCallbackUseCase.
-
class
intergov.use_cases.deliver_callback.
DeliverCallbackUseCase
(delivery_outbox_repo)[source]¶ Is used by a callback deliverer worker
- Reads queue delivery_outbox_repo consisting of tasks in format:
(url, message)
Then such message should be either sent to this URL and the task is deleted or, in case of any error, not to be deleted and to be tried again (up to MAX_RETRIES times)
TODO: rate limits, no more than 100 messages to a single url per 10 seconds?