Skip to content

core.messaging.design

Brian Greco edited this page Feb 12, 2022 · 9 revisions

Messaging Component Design

As part of the CQRS pattern, queries are separated from commands. The core messaging plugin supports sending commands and publishing domain events. In-process delivery of messages is supported by default. Other technology specific plugins, such as RabbitMQ, can extend the pipeline by implementing custom publishers. Below is an illustration of the key components contained within the implementation.

IMAGE

IMessage

Interface identifying a message that is handled by a consumer. There are two types of messages:

  • ICommand: Represents a message that updates the state managed by a Microservice.
  • IDomainEvent: Represents a message that notifies other subscribing components that a change was made to the the domain managed by the Microservice.

MessagingService

Central service used to dispatch queries, send commands, and publish domain events. For dispatching messages, the service delegates to the MessageDispatcher instance.

IMessageConsumer

Marker interface identifying components that can handle messages.

MessageDispatchModule

Plugin module responsible for locating all IMessageConsumer concrete classes and registering them as services with a scoped lifetime. The consumer message handlers are identified as any defined method passed a IMessage parameter and marked with the InProcessHandler attribute.

IMessageEnricher

Interface implemented by a classes responsible for adding key/value pairs to a passed message. Implementations can set common property values on all messages consistently from a central location. For example, the below are two default enrichers:

  • DatePublishedEnricher: Adds a key/value with the date the message was published.
  • CorrelationEnricher: Adds a GUID key/value used to identify the message.

MessageEnricherModule

Plugin module, when initialized, registers all configured IMessageEnricher concrete types within the service collection as scoped services.

IMessagePublisher

Interface implemented to extend the messaging pipeline to determine how messages are dispatched. The core messaging plugin and various other technology specific plugins provided IMessagePublisher implementations:

  • InProcessMessagePublisher: The default implementation that is automatically registered and dispatches messages to consumers located in the same process as the publisher.
  • RabbitMqPublisher: Registered when the NetFusion.RabbitMq plugin is added to the composite application. Allows specified messages to be delivered, out of process, to a message broker and processed by queue subscribers.
  • RedisPublisher: Allows specified messages to be delivered, out of process, to a Redis channel and processed by subscribers when the NetFusion.Redis plugin is added to the composite application.

MessageDispatcher

Plugin module responsible for dispatching a message by invoking all registered IMessageEnricher and IMessagePublisher instances.

Clone this wiki locally