Simple-Hooks is a solution to empower your app with events, and let other APIs to subscribe to various events. It posts the event data to every subscribed API.
All you have to do in your app is to trigger the event you want, by calling Simple-Hooks API.
Simple-Hooks will call all the subscribers, with the event data and retry on them in case of failure.
- dot net 8.0 framework
- SQL Server with DB for Simple-Hooks storage. Run the scripts in the repository path.
Simple-Hooks contains 2 components:
- Web API to trigger events. You need to host it under web server that support dot net 8.0 (IIS, Apache2, Nginx ...)
- Console Application to run in a scheduler (windows task scheduler or cron demon).
The setup is currently using SQL server scipts to DB. It is planned in the future to have web site for configuration.
just add a unique name for the event.
define the listener name, the URL to post the event data to, and the headers to be added to the HTTP request. You also define the timeout, the number of retries, and the period between each retry.
you will find a sample implementation of the listener in the repository path
associate the listeners to the events. You can have multiple listeners for the same event.
you need to include the event definition id, the event data, refernce name and reference value in the request body. note that the event data should be a string. in the string, you will add the data in json format.
{
"EventDefinitionId": "1",
"EventData": "{ 'ClientId': '34544433', 'ClientName': 'John Doe', 'ClientEmail': '[email protected]' }",
"ReferenceName": "client.techId",
"ReferenceValue": "abd123-1001"
}
simple hooks will post the listener definition headers and the event data along with the metadata of the event to the listener url respecting the listener definition timeout. and in case of failure, it will retry respecting the listener definition retries and retries delay.
{
"ClientId": "34544433",
"ClientName": "John Doe",
"ClientEmail": "[email protected]",
"simpleHooksMetadata": {
"eventDefinitionId": 1,
"eventDefinitionName": "Test Event 1",
"eventBusinessId": "5d364e8f-c27c-4e3d-9889-41fc40ba78b2",
"eventCreateDate": "2024-07-01T09:47:06.29",
"eventReferenceName": "client.techId",
"eventReferenceValue": "abd123-1001"
}
}
Metadata columns exist in every table for support purposes.
- Id: the identitiy of the row.
- CreateBy: the user who created the row.
- CreateDate: when the row was created.
- ModifyBy: the user last modified the row.
- ModifyDate: when the row last modified.
- Notes: notes about this row.
- Name: it is a unique name to identify the event.
- Active: marks if the event is active or not. If the event is not active, it cannot be triggered.
- Name: the name of the subscriber / listener.
- Active: marks if the listener is active or not. If the listener is not active, it will not be associated with the event(s) when triggered.
- URL: the url of the listener to be called when processing the event.
- Headers: the headers that will be added to the HTTP request when posting to the URL. multiple headers allowed. Each header on separate line. as the following sample:
content-type:application/json
token:65yrbwiw752342kjhjljwhlsf
- Timeout: when the HTTP request will timeout. In minutes.
- TrialCount: the max number of retries on the request if not succeeded to decalre its failure.
- RetrialDelay: the period between each retry. In minutes.
- EventDefinition_Id: Id of event definition row.
- ListenerDefinition_Id: Id of the related listener.
- Active: marks if the relation between the event definition and listener definition is active. If the relation is not active, it will not be associated with the event when triggered.
- EventDefinition_Id: Id of event definition row.
- BusinessId: event instance Id to be communicated in the event data.
- EventData: JSON data that will be post to all the subscribers / listeners when processing the events.
- ReferenceName: name of the reference for that particular event instance. (example: "ClientId" in case the event definition is "Client Added").
- ReferenceValue: value of the reference for that particular event instance. (example: "34544433" which is the value of the Client Id being added in "Client Added" event).
- EventInstanceStatus_Id: Id of the status of the event instance.
- Active: marks if the event instance is active. Only active event intance will be processed.
- EventInstance_Id: the Id of the related event instance.
- ListenerDefinition_Id: the Id of the lsitener definition.
- ListenerInstanceStatus_Id: Id of the status of the listener instance.
- RemainingTrialCount: the remaining number of retrials that can be executed on this listener instance.
- NextRun: when the next time this listener instance will be used in the post request.
- Acitve: marks if the listener instance is active. Only active listeners are processed.
- Name: name of the status. It can have one of the following values:
1.1. InQueue | 1: waiting to be processed.
1.2. Processing | 2: currently under processing.
1.3. Hold | 4: on hold. used in support as a temporary status.
1.4. Succeeded | 8: all listeners succeeded.
1.5. Failed | 16: at least one of the listeners failed.
1.6. Aborted | 32: aborted. used in support as a final status.
- Name: name of the status. It can have one of the following values:
1.1. InQueue | 1: waiting to be processed.
1.2. Processing | 2: currently under processing.
1.3. Hold | 4: on hold. used in support as a temporary status.
1.4. Succeeded | 8: this listener called successfully.
1.5. Failed | 16: this listener failed after consuming all the retrials.
1.6. Aborted | 32: aborted. used in support as a final status.
1.7. WaitingForRetrial | 64: failed at least once, waiting for the next retrial.
This table contains configurations of Simple-Hooks
- Category: the category of the option.
- Name: the name of the option.
- Value: the value of the option.
- Active: marks if the option is currently active.
- TopCount of the GetNotProcessed operation. It determines the number of event instance rows returns every time the opertation of processing events started.
- LogType: the Id of the type of the log.
- Owner: who added the log.
- Machine: the machine related to the log.
- Location: the assembly location on the machine.
- Operation: name of the operation.
- Step: name of the step in the operation.
- Counter: the number of the log in the same step in the same operation. Used for ordering the logs in the same step or different steps.
- Correlation: Id to unidfy different logs in the same step or the same operations.
- CodeReference: Namespace, class name, method name,...
- ReferenceName: name of a key reference related to the log.
- ReferenceValue: value of the key reference related to the log.
- NotesA: large text to describe data. Most of the time used to log parameters' values.
- NotesB: large text to describe data. Most of the time used to log error details.
- Duration: when calculation method execution duration.
- Name: name of the type of the log.
Log Types
- Debug | 1
- Information | 2
- Warning | 4
- Error | 8