1.0.3 • Published 5 years ago

kimono-wrapper v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

kimono-wrapper

šŸ‘˜ Kimono is a typesafe, promise based wrapper for node-nats-streaming. Now develop with confidence without worrying about your cluster ID, client ID and message payload. Just an enum to rule 'em all.

How to use

Install using npm install kimono-wrapper service.ts

import { Listener, Publisher } from 'kimono-wrapper';
import { Message } from "node-nats-streaming";

enum Subjects {
  TransactionDebit = "transaction:debit",
  TransactionCredit = "transaction:credit"
}

export interface TicketCreatedEvent {
  subject: Subjects.TicketCreated;
  data: {
    id: string;
    title: string;
    price: number;
  };
}

/**
 * Listener class implementation
 */
class TransactionDebitListener extends Listener<TransactionDebitListener, Subjects> {
  subject: Subjects.TransactionDebit = Subjects.TransactionDebit;
  queueGroupName = "payments-service";
  this.debug = false;
  
  onMessage(data: TransactionDebitEvent["data"], msg: Message): void {
    debug ? console.log(`Event data: ${data}`) : null;
	msg.ack();
  }
}

/**
 * Publisher class implementation
 */
class TransactionDebitPublisher extends Publisher<TransactionDebitEvent, Subjects> {
 subject: Subjects.TransactionDebit = Subjects.TransactionDebit;
}

/**
 * Publishing event
 */
new TransactionDebitPublisher(natsWrapper.client).publish({
  id: 'foo';
  title: 'bar';
  price: 10;
});
1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago