3.0.2 • Published 2 years ago

@adhityan/gc-nats v3.0.2

Weekly downloads
56
License
MIT
Repository
github
Last release
2 years ago

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

2 years ago

3.0.1

3 years ago

3.0.1-test.1

3 years ago

3.0.0

3 years ago

2.6.0-test.2

3 years ago

2.6.0-0.2

3 years ago

2.6.0-0.1

3 years ago

2.6.0-test.1

3 years ago

2.5.0

3 years ago

2.4.0

3 years ago

2.3.4

3 years ago

2.3.2

3 years ago

2.3.1

3 years ago

2.3.3

3 years ago

2.3.0

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.3

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

0.0.23

4 years ago

0.0.21

4 years ago

0.0.22

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.15

4 years ago

0.0.16

4 years ago

0.0.14

4 years ago

0.0.11

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago