如何解决微服务RabbitMQ回调API
你好,我对如何在编排场景中使用Rabbitmq感到怀疑,我也想拥有一个错误处理程序,所以我有以下疑问:
我应该为Rabbitmq服务器创建一个容器以进行回调 还是我会在每个服务中使用回调API创建Rabbitmq服务器?
RabbitMq服务器
export default class RabbitmqServer {
private connenction: Connection;
private channel: Channel;
private logger = logger;
constructor(private uri: string) {}
startRabbitMQ() {
connect(this.uri,(error: Error,connection: Connection) => {
if (error) {
this.logger.error(error.message);
setTimeout(this.startRabbitMQ,10000);
}
//listener on error
connection.on('error',(err: Error) => {
this.logger.error(err.message);
setTimeout(this.startRabbitMQ,10000);
});
//listener on close
connection.on('close',() => {
this.logger.error('connection to RabbitQM closed!');
setTimeout(this.startRabbitMQ,10000);
});
this.connenction = connection;
});
}
createChannel = () => {
this.connenction.createChannel((error: Error,channel: Channel) => {
if (error) this.logger.error(error.message);
channel.on('error',(errorOnChannel: Error) => {
this.logger.error('[AMQP] channel error',errorOnChannel.message);
});
channel.on('close',() => {
this.logger.error('[AMQP] channel closed');
});
this.channel = channel;
});
};
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。