Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated code snippets in docs. #10

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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