我有两个Rabbitmq nestjs微服务。两种服务都监听同一个队列
消息流:
MyQueue(pattern: events) -> ServiceA -> MyQueue(pattern: logs) -> ServiceB
消息流运行正常,但是当ServiceA向ServiceB发送消息时,我得到以下错误日志
[Server] There is no matching event handler defined in the remote service.
现在的问题是,在NestJS中是否假定服务应侦听所有传入的消息模式?如果否,那么如何处理此错误?
代码:
/*
* ServiceA
*/
import {EventPattern} from '@nestjs/microservices';
export class EventsController {
private client: ClientProxy;
constructor() {
this.client = ClientProxyFactory.create(getRabbitMQClientOptions());
}
@EventPattern('events')
handleEvents(data) {
this.client.emit('logs', data);
// process
}
}
/*
* ServiceB
*/
import {EventPattern} from '@nestjs/microservices';
export class LogsController {
@EventPattern('logs')
handleLogs(data) {
// handle logs
}
}
可能的解决方案:
使用不同的队列。但是然后我必须更改很多代码
注意: 如果找不到匹配的处理程序,则会记录错误的NestJS代码。 Github code link