0.6.2 • Published 1 day ago

@mojaloop/platform-shared-lib-messaging-types-lib v0.6.2

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
1 day ago

Mojaloop vNext - Platform Shared Libraries - Messaging Types Library

Git Commit Npm Version NPM Vulnerabilities CircleCI

Generic Messaging Types Library for the vNext Mojaloop platform. These types are meant to be stable, thus can be used in domain code. Note: for domain usage, actual implementations should be dependency-injected from outside the domain.

Generic Message Types

export enum MessageTypes{
    'STATE_EVENT' =0,           // for private event-sourcing events
    'STATE_SNAPSHOT',           // for private event-sourcing snapshot events
    'DOMAIN_EVENT',             // public domain events
    'COMMAND',                  // for internal/private BC commands
}

export interface IMessage{
    msgType: MessageTypes;
    msgName: string;             // name of the event or command
    msgId: string;               // unique per message
    msgTimestamp: number;
    msgTopic: string;
    msgKey: string | null;       // usually the id of the aggregate (used for partitioning)
    msgPartition: number | null;
    msgOffset: number | null;

    payload: any;                // this the actual message payload, specific to each type of msg
}

Base Domain Message Types (including aggregate identification)

export interface IDomainMessage extends IMessage{
    aggregateName: string       // name of the source/target aggregate (source if event, target if command)
    aggregateId: string         // id of the source/target aggregate (source if event, target if command)
}

export abstract class DomainMsg implements IDomainMessage {
    msgId: string = Crypto.randomUUID();
    msgTimestamp: number = Date.now();
    msgName: string = (this as any).constructor.name;
    msgPartition: number | null = null;
    msgOffset: number | null;

    abstract msgType: MessageTypes;
    abstract msgKey: string;
    abstract msgTopic: string;

    abstract aggregateId: string;
    abstract aggregateName: string;

    abstract payload: any
}

Specific Domain Message Types to extend from

General Domain events

Domain code emits these to advertise the facts that somehting itneresting happened inside that domain, and other apps might be interested int

These are usually public, any code inside the platform can listen to these

export abstract class DomainEventMsg extends DomainMsg {
    msgType: MessageTypes = MessageTypes.DOMAIN_EVENT;
}

State events to be used in event-sourcing scenarios

These are usually private to the publishing BCs/applications - no other apps should be allowed to listen them (exception is in CQRS pattern where an event handler of the same BC is creating a query data store from these events)

export abstract class StateEventMsg extends DomainMsg {
    msgType: MessageTypes = MessageTypes.STATE_EVENT;
}

Command messages events to be used in event-sourcing scenarios

These are usually private to the publishing BCs/applications - no other apps should be allowed to listen them (exception is in CQRS pattern where an event handler of the same BC is creating a query data store from these events)

export abstract class CommandMsg extends DomainMsg {
    msgType: MessageTypes = MessageTypes.COMMAND;
}

Message Consumer and Publisher interfaces

These interfaces provide an abstraction layer over specific infrastructure implementation, facilitating mocks and a future change from Kafka (if beneficial/necessary). They are stable and can be used in Domain Code, provided the domain code only depends on this lib and not actual implementation libs.

All implementation of message consumers and producer intended for general use must implement these interfaces.

In this repo we provide the implementation for Kafka here - Its npm module

IMessageConsumer

export interface IMessageConsumer {
    setCallbackFn: (handlerCallback: (message: IMessage) => Promise<void>) => void
    setFilteringFn: (filterFn: (message: IMessage) => boolean) => void
    setTopics: (topics: string[]) => void
    
    destroy: (force: boolean) => Promise<void>
    
    connect: () => Promise<void>
    disconnect: (force: boolean) => Promise<void>
    start: () => Promise<void>
    stop: () => Promise<void>
}

IMessageProducer

export declare interface IMessageProducer {
    destroy: () => Promise<void>

    connect: () => Promise<void>
    disconnect: () => Promise<void>

    send: (message: IMessage | IMessage[]) => Promise<void>
}
0.6.2

1 day ago

0.6.1

1 day ago

0.5.7

1 month ago

0.5.6

2 months ago

0.5.5

3 months ago

0.5.4

3 months ago

0.5.3

4 months ago

0.5.0

5 months ago

0.5.2

5 months ago

0.2.103

6 months ago

0.2.102

6 months ago

0.2.101

10 months ago

0.2.96

12 months ago

0.2.95

12 months ago

0.2.94

1 year ago

0.2.93

1 year ago

0.2.92

1 year ago

0.2.91

1 year ago

0.2.90

1 year ago

0.2.99

11 months ago

0.2.98

12 months ago

0.2.97

12 months ago

0.2.89

1 year ago

0.2.88

1 year ago

0.2.87

1 year ago

0.2.100

11 months ago

0.2.85

1 year ago

0.2.84

1 year ago

0.2.83

1 year ago

0.2.82

1 year ago

0.2.81

1 year ago

0.2.80

1 year ago

0.2.86

1 year ago

0.2.74

1 year ago

0.2.73

1 year ago

0.2.72

1 year ago

0.2.79

1 year ago

0.2.78

1 year ago

0.2.77

1 year ago

0.2.76

1 year ago

0.2.75

1 year ago

0.2.69

1 year ago

0.2.68

1 year ago

0.2.67

1 year ago

0.2.71

1 year ago

0.2.70

1 year ago

0.2.63

1 year ago

0.2.62

1 year ago

0.2.61

1 year ago

0.2.60

1 year ago

0.2.27

1 year ago

0.2.26

1 year ago

0.2.25

1 year ago

0.2.24

1 year ago

0.2.23

1 year ago

0.2.66

1 year ago

0.2.22

1 year ago

0.2.65

1 year ago

0.2.21

1 year ago

0.2.64

1 year ago

0.2.20

1 year ago

0.2.19

1 year ago

0.2.18

1 year ago

0.2.17

1 year ago

0.2.52

1 year ago

0.2.51

1 year ago

0.2.50

1 year ago

0.2.59

1 year ago

0.2.58

1 year ago

0.2.57

1 year ago

0.2.56

1 year ago

0.2.55

1 year ago

0.2.54

1 year ago

0.2.53

1 year ago

0.2.41

1 year ago

0.2.40

1 year ago

0.2.49

1 year ago

0.2.48

1 year ago

0.2.47

1 year ago

0.2.46

1 year ago

0.2.45

1 year ago

0.2.44

1 year ago

0.2.43

1 year ago

0.2.42

1 year ago

0.2.39

1 year ago

0.2.30

1 year ago

0.2.38

1 year ago

0.2.37

1 year ago

0.2.36

1 year ago

0.2.35

1 year ago

0.2.34

1 year ago

0.2.33

1 year ago

0.2.32

1 year ago

0.2.31

1 year ago

0.2.29

1 year ago

0.2.28

1 year ago

0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago