npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mojaloop/platform-shared-lib-messaging-types-lib

v0.7.1

Published

mojaloop vnext platform shared libraries - generic messaging types lib

Downloads

1,519

Readme

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>
}