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(","),
},
};
interface ICreateCompany {
subject: Subjects.CompanyCreated;
data: { id: number; name: string };
}
class ExampleStream extends BaseStream<ICreateCompany> {
subject: Subjects.CompanyCreated = Subjects.CompanyCreated;
queueGroupName: string = "sample group";
protected async onMessage(data: any, msg: JsMsg): Promise<void> {
console.log(data);
msg.ack();
}
}
export async function testConnection() {
const stream = new ExampleStream(CONFIG);
await stream.connect();
await stream.publish({ id: 10, name: "company" });
await stream.publish({ id: 20, name: "company" });
await stream.publish({ id: 30, name: "company" });
await stream.listen();
await stream.close();
}