Skip to main content.

Site Map

Site Map

Eventing

A microservice should provide an eventing mechanism for integration.

Eventing is used to let other domains within our microservice become aware of changes (inra-process communication). It is also used to allows other microservices to become aware of changes (inter-process communication).

We provide (3) three types of eventing in our platform, all of which can be customized with our Business Rule engine.

  • Broadcast (inter-process) - is an event that is sent via Service Bus using asynchronous communication to inform other microservice subsystems of a change.
  • Event (intra-process) - is an event that is occurring as apart of a defined process and you want other Domain Objects to be aware of the change.
  • Process (intra-process) - is an event that executes a packaged set of logic and instructions that can be customized as a whole.

Domain Broadcast

A Domain Broadcast is a message sent using asynchronous communication to inform other microservice subsystems of a change. We provide Service Bus integration for inter-process communication between microservies. You can choose between in-memory, single receiver (Queues) or multi-receiver (Topics and Subscriptions).

The following defines an example Broadcast that occurs when a MyDomainObject is changed. You could send only the properties that have been changed, or in this case, send the whole object.


    public class MyDomainObjectNameChangedBroadcast : DomainBroadcast<MyDomainObjectDto>
    {
        public MyDomainObjectNameChangedBroadcast(MyDomainObjectDto obj)
        {
            DomainObject = obj;
        }
    }

In order to send this message over service bus, we must obtain a reference to IServiceBus via depencency injection.


    public async Task MyExampleDependencyInjection(IServiceBus serviceBus)
    {
        var myObj = new MyDomainObject();
        myObj.Name = "New Name";
        var broadcast = new MyDomainObjectNameChangedBroadcast(myObj);
        await serviceBus.Send(broadcast);
    }

The Service Bus plumbing takes care of sending and receiving the Broadcast messages for you. In order to receive a Broadcast message, you define a Business Rule that is registered to the Broadcast message type. After defining a business rule, it is registred with dependency injection using the RegisterBrick() extension method. Using ServiceBus.Subscribe() registers the event with the Business Rule Registry and it additionally creates a subscription (if needed) with Service Bus.


        public static void RegisterRule(IServiceProvider serviceProvider)
        {
            var serviceBus = serviceProvider.GetRequiredService<IServiceBus>();
            serviceBus.Subscribe(
                typeof(MyDomainObjectNameChangedBroadcast),
                typeof(MyCustomBroadcastBusinessRule));
        }

View our section on Business Rules to learn more.

Domain Event

A Domain Event is a message that is occurring as apart of a defined process and you want other Domain Objects in your microservice to be aware of a change.

The following defines an example Domain Event that occurs when a MyDomainObject is changed. You could send only the properties that have been changed, or in this case, send the whole object. It is identical to a Domain Broadcast, except the inherited type is DomainEvent instead of DomainBroadcast.


    public class MyDomainObjectNameChangedEvent : DomainEvent<MyDomainObjectDto>
    {
        public MyDomainObjectNameChangedBroadcast(MyDomainObjectDto obj)
        {
            DomainObject = obj;
        }
    }

In order to raise this event, we must obtain a reference to the IBusinessRuleService via depencency injection.


    public async Task MyExampleDependencyInjection(IBusinessRuleService businessRuleService)
    {
        var domainObject = new MyDomainObject();
        domainObject.Name = "Hello World";

        var domainEvent = new MyDomainObjectNameChangedEvent(domainObject);
        var context = new BusinessRuleContext(domainEvent);
        var response = await businessRuleService.ExecuteDomainRulesAsync(context);
    }

Domain Process

A Domain Process is identical to a Domain Event, except that it executes a packaged set of logic and instructions that can be customized as a whole. While a Domain Event occurs within a defined process, a Domain Process is a process in of itself. a Domain Process is like having an API method with only one line of code which is to raise a domain event.

A Domain Process is unique to our platform and is based on our business rule engine. This allows you to replace the functionality completely, or add pre-processing or post-processing instructions for unparalleled customization. It is apart of the SERVICE BRICK foundation that allows you to customize any of our pre-built services to your own needs, quickly.