-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
After the installation, you need to place two pieces to make it work
Event Manager section in appsettings.json Here you will define the ExternalServices and Subscriptions/Events to be exposed so you can later register to these events. The events are not fired here, that occurs in the code, but this definition allows you to say "when I fire this event, this endpoint will be called".
Add an EventManager section at appsettings.json in your C# web application, it must have two sections, one for external services and the other for subscriptions.
ExternalServices defines a Server or Service to be called with an exposed endpoint, each external service has a name, this name is used in the subscription section, so you can have multiple subscriptions attached to the same external service, therefore, firing multiple events.
The endpoint to be called is defined in the Subscriptions section, you add an EventName that you will use later in the code to register to that event.
appsettings.json EventManager section example
"EventManager": {
"ExternalServices": [
{
"Name": "httpbin",
"Config": {
"BaseUrl": "https://httpbin.org/ ",
"MaxRetries": 10,
"RequestRate": 312
},
"Auth": {
"Type": "None",
}
},
],
"Subscriptions": [
{
"EventName": "my_custom_event_name",
"Subscribers": [
{
"Name": "httpbin",
"Method": "POST",
"Endpoint": "/post"
},
]
}
]
},A ExternalService represents a server with endpoints that will be consumed in a Subscription.
Name to identify the ExternalService and to use as reference to bind the subscriber in the Subscription section
The Config Section is in charge of the setup of this service
- BaseURL: Protocol and Hostname e.g: https://httpbin.org
- MaxRetries: How many times should the EventManager try again if the endpoint fails
- RequestRate: In case of the endpoint failing, how many times should it try again per second. The time is calculated dividing 1000 milliseconds by the RequestRate
millisecondRate = 1000 / RequestRate
The Auth Section defines the Authorization types available to this ExternalService, meaning that then it should provide specific properties for that specific Authorization type
The following are the Authorization Types available and their properties required for it to work
A None type is just a regular call to an Endpoint without any kind of authorization, like calling any page with a GET
{
"Auth": {
"Type": "None"
}
}A Basic type is for an endpoint that at the same time of a call, requires for you to provide a Username and a Password. More details here: https://en.wikipedia.org/wiki/Basic_access_authentication
{
"Auth": {
"Type": "Basic",
"Username": "guest",
"Password": "guest"
}
}This version of OAuth authorization is called OAuthClientPassword, there will be others in the future, but this is the one we offer support now.
{
"Auth": {
"Type": "OAuthClientPassword",
"LoginEndpoint": "https://test.salesforce.com/services/oauth2/token ",
"ClientId": "3MVG9JamK_x9K2XLyVoXrM8XKmuFlmSrGXqN3Cg0.SvKRLVF7eXWoKMW88L.KftkD0e5yQ_UAqu8aEuK5Li.m",
"ClientSecret": "49BBC4F7AA6CF2071771D1D940746A122A56BCF428021A2462A707AC4DE479FE",
"Username": "user_test.16072020@hotmail.com",
"Password": "testCAREERS16072020",
"Token": "iUQYHVnzpR2D37YDgUmNyomjc"
}
}Note: a OAuthClientPassword has no BaseURL in the ExternalServices.Config section, this because it has a LoginEndpoint, which is the place where the process of authentication starts, after the authentication is granted internally a BaseURL is given by the ExternalService and this url is used with the Endpoint added with its Subscriber inside the Subscription section.
{
"Subscriptions": [
{
"EventName": "my_custom_event_name",
"Subscribers": [
{
"Name": "httpbin",
"Method": "POST",
"Endpoint": "/post"
}
]
}
]
}Name of the event, it can be any name, it will be used as a Unique Identifier inside your code to bind a callback to the event
Here you define a list of endpoints that will be called when the Event is fired, on this case https://httpbin.org/post will be called when the event is fired
This name is different to EventName, this name is matched with the ExternalServices name, so the endpoint will be attached to the ExternalService BaseURL
This is the HTTP Method to execute this url, these can be GET, POST, PUT, DELETE, etc, more info here: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods
The endpoint to be called without the BaseURL, on this example it's just /post, because the BaseURL is already set on ExternalServices as https://httpbin.org/
Add the following line of code into Startup.cs in the ConfigureServices method
services.Configure<EventManagerConfiguration>(Configuration.GetSection("EventManager"));Also add the following call. This method will allow you to register Subscription to Events
services.ConfigureCecEventManager((EventDispatcher eventDispatcher) =>
{
/*
Register Calls here
eventDispatcher.RegisterLocal(...)
eventDispatcher.Register(...)
*/
}Add the following line of code into Startup.cs in the Configure method
app.UseCecEventManager();