@dvsa/business-events
v1.1.0
Published
A package to help manage business events in a domain context.
Downloads
69
Readme
@dvsa/business-events
Helper library for publishing business events.
Pre-requisites
- Node.js (Please see
.nvmrc
in the root of the repo for a specific version) npm
(If using n or nvm, this will be automatically managed)- Security
- Git secrets
- ScanRepo
- Unzip
repo-security-scanner_<version>_Darwin_<architecture>.tar.gz
and rename the executable inside the folder toscanrepo
- Add executable to path (usingecho $PATH
to find your path)
- Unzip
Getting started
Run the following command after cloning the project
npm install
(ornpm i
)
Using this package
Extend the EventFactory
class as demonstrated in the TestSystemEventFactory
class. This pattern will allow the encapsulation of all business events for a particular domain e.g.
export class EnquirySystemEventFactory extends EventFactory {
constructor(correlationId: string) {
super(correlationId);
}
public feedJobInitiated = (feedType: string) =>
super.create('ENQ_SYSTEM_DOMAIN_EVENTS', 'ENQ_UPDATE_NOP_INITIATED', feedType);
}
With a domain-specific event factory, generate a business event and call the BusinessEventPublisher.publish
function.
const feedJobInitiatedEvent =
EnquirySystemEventFactory.fromSqsRecord(sqsRecord).feedJobInitiated('evl');
BusinessEventPublisher.publish(feedJobInitiatedEvent);
Recommendations
Publishing business events should not impact the operation of a system. Failures should be logged and monitored, however the system should not respond to any errors in a way that impacts the expected behaviour of the system.