Skip to content

Commit

Permalink
updated code snippets in docs. (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
tamimaj authored Oct 22, 2023
1 parent 52b55c4 commit 79d8a39
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bootstrap();
</p>

```ts
import { Ctx, MessagePattern, Payload } from '@nestjs/microservices';
import { Ctx, Payload } from '@nestjs/microservices';
import {
RedisStreamHandler,
StreamResponse,
Expand Down Expand Up @@ -181,11 +181,12 @@ When you have your redis connection config, streams config, etc, beforehand and
In your app.module.ts or any other module you want to use the client to publish streams:

```ts
import { RedisStreamsClientModule } from '@tamimaj/nestjs-redis-streams';
import { Module } from '@nestjs/common';
import { RedisStreamClientModule } from '@tamimaj/nestjs-redis-streams';

@Module({
imports: [
RedisStreamsClientModule.register({
RedisStreamClientModule.register({
connection: { url: '0.0.0.0:6379' },
streams: { consumer: 'api-1', block: 5000, consumerGroup: 'api' },
responseStreams: ['users:created', 'users:created:copy'],
Expand All @@ -204,12 +205,14 @@ When you don't have your redis connection config, streams config, beforehand, or
In your app.module.ts or any other module you want to use the client to publish streams:

```ts
import { RedisStreamsClientModule } from '@tamimaj/nestjs-redis-streams';
import { Module } from '@nestjs/common';
import { RedisStreamClientModule } from '@tamimaj/nestjs-redis-streams';
import { ConfigModule, ConfigService } from '@nestjs/config';

@Module({
// more examples about useClass, useFactory, in the example client app.
imports: [
RedisStreamsClientModule.registerAsync({
RedisStreamClientModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
connection: configService.get('REDIS_CONNECTION'),
Expand All @@ -236,18 +239,21 @@ Check the example app to see how to use the client to publish streams.
In your service or controller:

```ts
import { Controller, Get } from '@nestjs/common';
import { RedisStreamClient } from '@tamimaj/nestjs-redis-streams';
import { lastValueFrom } from 'rxjs';

@Controller()
export class AppController {
constructor(private readonly redisStreamClient: RedisStreamClient) {} // inject the client.

@Get('/send')
async sendMessage(): Promise<any> {
// send a message and get a response.

const observable = this.redisStreamClient.send('stream:name:here', {
data: { name: 'tamim' }, // will be JSON.stringify() and stored in the data key.
anyOtherHeadersKey: 'anyOtherHeadersValue', // header key, will be kept as key/value.
anyOtherHeadersKey: 'anyOtherHeadersValue', // header key, will be kept as key/value.
});

const response = await lastValueFrom(observable); // get the last value from the observable.
Expand All @@ -266,18 +272,19 @@ export class AppController {
In your service or controller:

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

@Controller()
export class AppController {
constructor(private readonly redisStreamClient: RedisStreamClient) {} // inject the client.

@Get('/emit')
async getHelloEmit(): Promise<any> {
async emitMessage(): Promise<any> {
// emit a message and don't wait for a response.
// fire and forget.

const observable = this.redisStreamClient.emit('stream:name:here', {
this.redisStreamClient.emit('stream:name:here', {
data: { name: 'tamim', fireAndForgetEvent: true }, // main key.
anyOtherHeadersKey: 'anyOtherHeadersValue', // header key, will be kept as key/value.
});
Expand Down
2 changes: 1 addition & 1 deletion examples/client-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/users-microservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tamimaj/nestjs-redis-streams",
"version": "1.0.1",
"version": "1.0.2",
"description": "Redis Streams Transport for NestJS.",
"author": "Tamim Abbas Aljuratli <https://tamim.es>",
"private": false,
Expand Down

0 comments on commit 79d8a39

Please sign in to comment.