Application construction components - Altinn Platform Events
The Events component in Altinn platform is constructed as an asp.net core web API application deployed as a docker container to a Kubernetes cluster.
The Events components expose REST-APIs for publishing and subscribing to events.
When a publish request is received it will push the event document to the event storage. When a request is received it will query the events stored in the event storage.
The following API controllers are defined
- EventsController : responsible for registrating events and pull of events for consumers.
- PushController : responsible to validate if there is any subscriptions matching the event and if so authorize the subscriper before it pushes the event to the outbound queue
- SubscriptionController : responsible for managing subscriptions for consumers.
The eventscontroller in the Events component is the one receiving events from Apps and other sources.
It verifies if the app is authorized to creates events for the given source and then store in to event storage
Push Events controller
Push Events controller is called by the InboundEventsController. Based on details from the Event it will identify matching subscriptions. For each match it will authorize the consumer using the Policy Authorization Point.
The AuthorizationHelper is responsible for creating and performing the request.
To be able to get the search capability needed for the Events component we have choosen to use PostgreSQL.
Using PostgreSQL makes is possible to sort the events based on a primary key and also makes it possible to search over all events based on subject or source.
The suggested table structure
CREATE TABLE events( sequenceno BIGSERIAL PRIMARY KEY, id VARCHAR NOT NULL, source VARCHAR NOT NULL, subject VARCHAR NOT NULL, type VARCHAR NOT NULL, time timestamptz NOT NULL, cloudevent TEXT NOT NULL );
Events will be sequnced by sequence number that is the primary key of the Events table.
We would need to have index on
As part of the Event Component there is 3 Azure Functions used for pushing events to the consumers. Click on name for code.
- EventsInbound : responsible for pushing new events to the push controller
- EventsOutbound : responsible for pushing event to consumer webhook
- ValidateSubscription : responsible for validating the endpoint given in a subscription.
The EventsInbound function is triggered by QueueStorage changes in the “events-inbound” queue.
It just forward the event to the PushController through the pushEventService.
The Function uses Platform Access token to authenticate itself for the PushController
It uses standard mechanismen for retry, if the call for pushcontroller fails.
The EventsOutbound function is triggered byQueueStorage changes in the “events-outbound” queue.
It will try to push the event to given subscription endpoint given in the CloudEventEnvelope that is put on the queue and containing the event.
This function is configured with CustomQueueProcessorFactory to handle retry if it is not possible to push event to the endpoint.
It will try send the event right away, but if the request to webhook fails it will put the cloudevent back on the queue with a defined wait time.
- retries after 10 seconds
- retries after 30 seconds
- retries after 1 minute
- retries after 5 minutes
- retries after 10 minutes
- retries after 30 minutes
- retries after 1 hour
- retries after 3 hours
- retries after 6 hours
- retries after 12 hours
- retries after 12 hours
If it fails the 12. time it will put the event in the dead letter queue and will not try again.