Skip to main content

Transport

Messaging

Strategy

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

Checklist

What checklist do you need to evolve when selecting a transport layer for your dev stack?

Listeners

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
msg.ack();
}
}