2.1.20 • Published 6 months ago
vendease-common v2.1.20
vendease backend common
contains a set of common utility functions, classes, and modules that are used across the Vendease platform's backend system
Code example Jetstream setup
const CONFIG = {
connectionOptions: {
servers: ["localhost"],
name: process.env.APP_NAME ?? "e-procurement",
},
consumerOptions: {
deliverGroup: process.env.JETSTREAM_DELIVER_GROUP ?? "core-service-group",
durable: process.env.JETSTREAM_CONSUMER_DURABLE ?? "core-services-durable",
deliverTo: process.env.JETSTREAM_CONSUMER_DELIVER_TO ?? "core-services-deliver-to",
manualAck: Boolean(process.env.JETSTREAM_MANUAL_ACK ?? "true"),
},
streamConfig: {
name: process.env.JETSTREAM_STREAM_NAME || "core-services",
subjects: (process.env.JETSTREAM_STREAM_SUBJECTS || "core.*").split(","),
},
// host: process.env.NATS_HOST || 'demo.nats.io',
// port: Number(process.env.NATS_PORT) || 4222,
};
interface ICreateCompany {
subject: Subjects.CompanyCreated;
data: { id: number; name: string };
}
interface IUserCreatedCompany {
subject: Subjects.UserCreated;
data: { id: number; first_name: string; last_name: string };
}
// Singleton
class SingleInstanceStream extends BaseStream {
queueGroupName: string = "sample group";
protected async onMessage(data: any, msg: JsMsg): Promise<void> {
console.log(data);
console.log(msg.subject);
switch (msg.subject) {
case "Subjects.UserCreated":
return this.handleUserCreated(data);
case Subjects.CompanyCreated:
return this.handleCompanyCreated(data);
default:
return "i probably don't understand this message";
}
msg.ack();
}
}
export async function testConnection() {
const stream = new SingleInstanceStream(config);
await stream.connect();
await stream.publish<IUserCreatedCompany>(Subjects.UserCreated, { id: 20, first_name: "bola", last_name: "tinubu" });
await stream.publish<ICreateCompany>(Subjects.CompanyCreated, { id: 20, name: "dayo's company company created" });
await stream.listen();
await stream.close();
}
2.1.19
6 months ago
2.1.20
6 months ago
2.0.3
9 months ago
2.0.2
9 months ago
2.1.9
8 months ago
2.1.16
8 months ago
2.1.17
8 months ago
2.1.14
8 months ago
2.1.15
8 months ago
2.1.12
8 months ago
2.1.13
8 months ago
2.1.10
8 months ago
2.1.11
8 months ago
1.0.32
11 months ago
2.1.18
8 months ago
2.1.2
9 months ago
2.1.1
9 months ago
2.1.4
8 months ago
2.1.3
9 months ago
2.1.6
8 months ago
2.1.5
8 months ago
2.1.8
8 months ago
2.1.7
8 months ago
1.0.31
1 year ago
1.0.30
1 year ago
1.0.29
1 year ago
1.0.28
1 year ago
1.0.26
1 year ago
1.0.25
1 year ago
1.0.24
1 year ago
1.0.23
1 year ago
1.0.22
1 year ago
1.0.21
1 year ago
1.0.20
1 year ago
1.0.19
1 year ago
1.0.18
1 year ago
1.0.17
1 year ago
1.0.16
1 year ago
1.0.15
1 year ago
1.0.14
1 year ago
1.0.13
1 year ago
1.0.12
1 year ago
1.0.11
1 year ago
1.0.10
1 year ago
1.0.9
1 year ago
1.0.7
1 year ago
1.0.6
1 year ago
1.0.5
1 year ago
1.0.4
1 year ago
1.0.3
1 year ago
1.0.2
1 year ago
1.0.1
1 year ago