Message Producer
The IMessageProducer port defines how domain events are published from DugongJS as messages to external systems through a message broker.
IMessageProducer
The responsibility of the IMessageProducer is to publish one or more outbound messages based on metadata for a specific aggregate. Methods on the interface will receive the current transaction context provided by ITransactionManager which can be used to implement the outbox pattern, where a dedicated database table functions as an outbox and a transaction log miner acts as the message producer. It should be implemented like so:
import type { IMessageProducer } from "@dugongjs/core";
export class MessageProducer implements IMessageProducer<TMessage> {
// Implementation here...
}
Here, TMessage should be a type corresponding to the message format of the broker.
Related Ports
IMessageConsumer– listens to inbound messages.IOutboundMessageMapper– maps messages to domain events.ITransactionManager– used to ensure transactional consistency.