-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
EventHandler pattern fails to subscribe to Redis channel #7406
Comments
also posted on StackOverflow in case this is user error and not a bug |
Interestingly, if I try to take over the protected listen() {
this.client['subClient'].subscribe(EVENT_NAME);
this.client['subClient'].on('message', (channel, message) => {
console.log(`subClient received; channel=${channel}, message=${message}`);
});
} With this running, the controller handler still does not get triggered, but I can now see the messages come through in the logs: |
Please, provide a minimum reproduction repository on Github. |
Your minimum reproduction repository is invalid. In the await NestFactory.createMicroservice<RedisOptions>(AppModule, {
transport: Transport.REDIS,
options: { url: 'redis://localhost:6379' },
}); but since it's not assigned to any variable, it's automatically garbage collected (and the After making the following changes: everything will start working as expected: |
Thank you @kamilmysliwiec I suspected as much. May I suggest that at least one of the examples on the Microservices section of the docs shows or links to this I appreciate your time, and I'm a big fan of your project. |
Hello. The solution offered above creates two full instances of the application (I have 2 AppModules and everything else). This led to some hard to debug errors. In Kamil's solution, I changed this line:: const microservice = await NestFactory.createMicroservice<RedisOptions>(AppModule, {
transport: Transport.REDIS,
options: { url: 'redis://localhost:6379' },
}); To this: const microservice = app.connectMicroservice({
transport: Transport.REDIS,
options: { url: 'redis://localhost:6379' },
}); |
The relevant section of the documentation: |
Yep, that was just an example. Using hybrid apps approach is totally fine |
Bug Report
Current behavior
client.connect()
client.emit()
@EventPattern
does not get triggeredInput Code
Source code can be downloaded and run
main.ts
AppModule
AppController handler
TransportModule
Application Log
redis-cli log
In the redis-cli log above, the 3rd line of response to my subscribe call is
(integer) 1
; this leads me to believe that NestJS is not subscribed to this channel at all (that the redis-cli is the 1 subscriber)redis-server log
When the application starts up, the
redis-server
log shows two accepted connections on consecutive ports (I assume that's when I make theclient.connect()
call)Expected behavior
I expected that when I use
client.emit(EVENT_NAME)
, the controller handler decorated with@EventPattern(EVENT_NAME)
would be executed with the event payloadPossible Solution
Environment
Sorry for the long post. In case you missed it, the source files are available here.
The text was updated successfully, but these errors were encountered: