@@ -116,7 +116,7 @@ bootstrap();
116116</p >
117117
118118``` ts
119- import { Ctx , MessagePattern , Payload } from ' @nestjs/microservices' ;
119+ import { Ctx , Payload } from ' @nestjs/microservices' ;
120120import {
121121 RedisStreamHandler ,
122122 StreamResponse ,
@@ -181,11 +181,12 @@ When you have your redis connection config, streams config, etc, beforehand and
181181In your app.module.ts or any other module you want to use the client to publish streams:
182182
183183``` ts
184- import { RedisStreamsClientModule } from ' @tamimaj/nestjs-redis-streams' ;
184+ import { Module } from ' @nestjs/common' ;
185+ import { RedisStreamClientModule } from ' @tamimaj/nestjs-redis-streams' ;
185186
186187@Module ({
187188 imports: [
188- RedisStreamsClientModule .register ({
189+ RedisStreamClientModule .register ({
189190 connection: { url: ' 0.0.0.0:6379' },
190191 streams: { consumer: ' api-1' , block: 5000 , consumerGroup: ' api' },
191192 responseStreams: [' users:created' , ' users:created:copy' ],
@@ -204,12 +205,14 @@ When you don't have your redis connection config, streams config, beforehand, or
204205In your app.module.ts or any other module you want to use the client to publish streams:
205206
206207``` ts
207- import { RedisStreamsClientModule } from ' @tamimaj/nestjs-redis-streams' ;
208+ import { Module } from ' @nestjs/common' ;
209+ import { RedisStreamClientModule } from ' @tamimaj/nestjs-redis-streams' ;
210+ import { ConfigModule , ConfigService } from ' @nestjs/config' ;
208211
209212@Module ({
210213 // more examples about useClass, useFactory, in the example client app.
211214 imports: [
212- RedisStreamsClientModule .registerAsync ({
215+ RedisStreamClientModule .registerAsync ({
213216 imports: [ConfigModule ],
214217 useFactory : async (configService : ConfigService ) => ({
215218 connection: configService .get (' REDIS_CONNECTION' ),
@@ -236,18 +239,21 @@ Check the example app to see how to use the client to publish streams.
236239In your service or controller:
237240
238241``` ts
242+ import { Controller , Get } from ' @nestjs/common' ;
239243import { RedisStreamClient } from ' @tamimaj/nestjs-redis-streams' ;
244+ import { lastValueFrom } from ' rxjs' ;
240245
241246@Controller ()
242247export class AppController {
243248 constructor (private readonly redisStreamClient : RedisStreamClient ) {} // inject the client.
244249
250+ @Get (' /send' )
245251 async sendMessage(): Promise <any > {
246252 // send a message and get a response.
247253
248254 const observable = this .redisStreamClient .send (' stream:name:here' , {
249255 data: { name: ' tamim' }, // will be JSON.stringify() and stored in the data key.
250- anyOtherHeadersKey: ' anyOtherHeadersValue' , // header key, will be kept as key/value.
256+ anyOtherHeadersKey: ' anyOtherHeadersValue' , // header key, will be kept as key/value.
251257 });
252258
253259 const response = await lastValueFrom (observable ); // get the last value from the observable.
@@ -266,18 +272,19 @@ export class AppController {
266272In your service or controller:
267273
268274``` ts
275+ import { Controller , Get } from ' @nestjs/common' ;
269276import { RedisStreamClient } from ' @tamimaj/nestjs-redis-streams' ;
270277
271278@Controller ()
272279export class AppController {
273280 constructor (private readonly redisStreamClient : RedisStreamClient ) {} // inject the client.
274281
275282 @Get (' /emit' )
276- async getHelloEmit (): Promise <any > {
283+ async emitMessage (): Promise <any > {
277284 // emit a message and don't wait for a response.
278285 // fire and forget.
279286
280- const observable = this .redisStreamClient .emit (' stream:name:here' , {
287+ this .redisStreamClient .emit (' stream:name:here' , {
281288 data: { name: ' tamim' , fireAndForgetEvent: true }, // main key.
282289 anyOtherHeadersKey: ' anyOtherHeadersValue' , // header key, will be kept as key/value.
283290 });
0 commit comments