Skip to main content

Message Bus



NATs vs Rabbit MQ

Can use DB Transaction to record whether an event has been published to a queue.

Means saving two items per tranaction. One to the entity of interest the other to the event audit table. See detailed explanation

Mocking Message Bus for Tests


Standard signiture for a listener is:

import { Message } from "node-nats-streaming";
import { Subjects, Listener, TicketCreatedEvent } from "@stackmates/common";

export class TicketCreatedListener extends Listener<TicketCreatedEvent> {
subject: Subjects.TicketCreated = Subjects.TicketCreated;
queueGroupName = "orders-service";

onMessage(data: TicketCreatedEvent["data"], msg: Message) {
// extract data

// take action to persist

// if success acknowledge the message