1. Home
  2. Extensibility
  3. Delivery custom channel

Delivery custom channel

◷ Reading Time: 2 minutes

You can also create custom channels to store the events in anywhere that you need. For instance in a database, Azure blob storage and etc.

Custom Channels

When events are raised, you can receive signals in two forms:

  1. Static types
  2. JSON formats (string)
  3. Free text form (via GenericTraceEvent)

Build Custom Channel

In a custom channel, you can listen to events in two ways:

Using Write and WriteLine override of TraceListener. In these methods, the custom listener receives messages in a string with JSON structure or some other free text format if GenericTraceEvent is raised.

using FlexRule.Server.Events;
  
 class MyCustomListener : TraceListener
 {
     public MyCustomListener()
     {
     }
  
     public override void Write(string message)
     {
         //  message of the channel to process
     }
  
     public override void WriteLine(string message)
     {
         //  message of the channel to process
     }
 }

Handle Custom Events

The channel can listen to specific events, using configuration or using your code. For using code, the DomainEvents.Register should be used to subscribe to an event. In this approach, the custom listener receives signals as .Net Types.

using FlexRule.Server.Events;
  
 class MyCustomListener : TraceListener
 {
     public MyCustomListener()
     {
         // TYPE_OF_EVENT is the event type
         // Subscribe to an event...
         DomainEvents.Register(typeof(TYPE_OF_EVENT), eventHander);
         // when the event occurs, the eventHandler is called. 
     }
  
     private void eventHander(TYPE_OF_EVENT domainEvent)
     {
         // TYPE_OF_EVENT is the event type which this listener is subscribed to
     }
  
     public override void Write(string message)
     {
         //  Do nothing
     }
  
     public override void WriteLine(string message)
     {
         //  Do nothing
     }
 }

In the sample code above, TYPE_OF_EVENT is the place holder for the actual event type with the names that are listed in the section above.

Once the custom channel is derived from TraceListener, then to register a custom channel, use the configuration on Master and/or Agents and configure them as shown below:

  1. Register it with a name in the channels section.
  2. Assign the channel to events that you want to subscribe to using the monitoring/add section.
Updated on November 2, 2020

Was this article helpful?

Related Articles