Created
July 3, 2021 11:13
-
-
Save musou1500/d20f2a9e36c73ebf73fcbb3f09fa12c5 to your computer and use it in GitHub Desktop.
Example nestjs-graphql-redis-subscriptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Inject, ValidationPipe } from "@nestjs/common"; | |
import { NestFactory } from "@nestjs/core"; | |
import { Module } from "@nestjs/common"; | |
import { | |
IOModule, | |
RedisPubSub, | |
REDIS_PUB_SUB_TOKEN, | |
} from "nestjs-graphql-redis-subscriptions"; | |
class AppService { | |
constructor(@Inject(REDIS_PUB_SUB_TOKEN) private pubsub: RedisPubSub) {} | |
publish(trigger: string, payload: unknown): Promise<void> { | |
return this.pubsub.publish(trigger, payload); | |
} | |
} | |
@Module({ | |
controllers: [], | |
providers: [AppService], | |
imports: [ | |
IOModule.registerRedisPubSub( | |
// publisher connection | |
{ | |
useFactory: () => ({ | |
port: 6379, | |
host: "127.0.0.1", | |
}), | |
}, | |
// subscriber connection | |
{ | |
useFactory: () => ({ | |
port: 6379, | |
host: "127.0.0.1", | |
}), | |
} | |
), | |
], | |
}) | |
export class AppModule {} | |
async function bootstrap() { | |
const app = await NestFactory.create(AppModule); | |
app.useGlobalPipes(new ValidationPipe({ transform: true })); | |
await app.listen(3000); | |
} | |
bootstrap(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment