3.0.2 • Published 4 years ago
@adhityan/gc-nats v3.0.2
gc-nats
A TypeScript Node.js wrapper service for the NATS streaming server based on stan.js client.
Publishing messages
import "reflect-metadata";
import { JsonController, Get, Res } from 'routing-controllers';
import { Inject, Service } from 'typedi';
import { ResponseUtil } from '@app/utils';
import { NatsService } from '@buzzkey/gc-nats';
import { Logger } from '@adhityan/gc-logger';
@Service()
@JsonController('/v1')
export class PingController {
@Inject()
public natsService: NatsService;
@Get('/ping')
async ping(@Res() res: any) {
// send test ping message to queue
const channel: string = "ping";
const message: any = {
info: "testing ping"
};
const messageId: string = await this.natsService.publish(channel, message);
Logger.debug(`published message: ${messageId}`);
return ResponseUtil.ok({ message: 'Ping Successful' }, res);
}
}
Subscribing to messages from a channel/subject
import { natsConfig } from '@app/config/nats.config';
import { Logger } from '@adhityan/gc-logger';
import { Worker } from '@adhityan/gc-nats';
const subject = "ping";
@Worker<T>(natsConfig)
export class PingWorker {
static channel: string = subject;
public async messageReceived (message: T) {
Logger.debug('Ping successful. worker processing message: ', message);
}
}
3.0.2
4 years ago
3.0.1
4 years ago
3.0.1-test.1
4 years ago
3.0.0
4 years ago
2.6.0-test.2
4 years ago
2.6.0-0.2
4 years ago
2.6.0-0.1
4 years ago
2.6.0-test.1
4 years ago
2.5.0
4 years ago
2.4.0
4 years ago
2.3.4
4 years ago
2.3.2
4 years ago
2.3.1
4 years ago
2.3.3
4 years ago
2.3.0
4 years ago
2.2.2
4 years ago
2.2.1
4 years ago
2.2.0
4 years ago
2.1.0
4 years ago
2.0.3
5 years ago
2.0.1
5 years ago
2.0.0
5 years ago
0.0.23
5 years ago
0.0.21
6 years ago
0.0.22
6 years ago
0.0.20
6 years ago
0.0.19
6 years ago
0.0.18
6 years ago
0.0.17
6 years ago
0.0.15
6 years ago
0.0.16
6 years ago
0.0.14
6 years ago
0.0.11
6 years ago
0.0.12
6 years ago
0.0.10
6 years ago
0.0.9
6 years ago
0.0.8
6 years ago
0.0.7
6 years ago
0.0.5
6 years ago
0.0.4
6 years ago
0.0.3
6 years ago
0.0.2
6 years ago
0.0.1
6 years ago