Skip to content

Commit 79d8a39

Browse files
authored
updated code snippets in docs. (#10)
1 parent 52b55c4 commit 79d8a39

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
120120
import {
121121
RedisStreamHandler,
122122
StreamResponse,
@@ -181,11 +181,12 @@ When you have your redis connection config, streams config, etc, beforehand and
181181
In 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
204205
In 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.
236239
In your service or controller:
237240

238241
```ts
242+
import { Controller, Get } from '@nestjs/common';
239243
import { RedisStreamClient } from '@tamimaj/nestjs-redis-streams';
244+
import { lastValueFrom } from 'rxjs';
240245

241246
@Controller()
242247
export 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 {
266272
In your service or controller:
267273

268274
```ts
275+
import { Controller, Get } from '@nestjs/common';
269276
import { RedisStreamClient } from '@tamimaj/nestjs-redis-streams';
270277

271278
@Controller()
272279
export 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
});

examples/client-app/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/users-microservice/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tamimaj/nestjs-redis-streams",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Redis Streams Transport for NestJS.",
55
"author": "Tamim Abbas Aljuratli <https://tamim.es>",
66
"private": false,

0 commit comments

Comments
 (0)