简体   繁体   English

在PUB / SUB模型中使用RabbitMQ的消息

[英]Consuming messages from RabbitMQ in PUB/SUB model

In my project i have a requirement like different methods push sql queries to Rabbit queue (basically an exchange which broadcast messages to all queues). 在我的项目中,我有一个要求,就像不同的方法一样,将sql查询推送到Rabbit队列(基本上是将消息广播到所有队列的交换)。 These SQL queries pushed to queue are not very important at this point of time (basically for reporting purpose) when compare to production, so i will be executing these queries in different environment (some other standalone project) when i dont have much load on server. 与生产相比,这些推送到队列的SQL查询此时(基本上出于报告目的)不是很重要,因此当我在服务器上没有太多负载时,我将在不同的环境(某些其他独立项目)中执行这些查询。

Now lets get into part two of the story, In standalone application at other side have 2 consumers which consume messages (SQL queries) from RabbitMQ (exchange). 现在让我们进入故事的第二部分,在另一端的独立应用程序中,有2个使用者使用来自RabbitMQ(交换)的消息(SQL查询)。 One consumer always logs (like backup of queries) and other performs batch update/insert on DB. 一个使用者始终记录日志(例如查询的备份),而另一个使用者在数据库上执行批量更新/插入。

My issue is what is the good way to achieve this use case when few queries may fail because of several reasons and as it is batch operation , that entire batch is going to rollback and i cant get those from queue again as those were already consumed. 我的问题是实现这种用例的好方法是什么,当由于几种原因而导致少数查询失败并且由于是批处理操作时,整个批处理都将回滚,由于已经被消耗掉,我无法再次从队列中获取这些批处理。 I know that i have to get it from backup created by my 2nd consumer, but i have to stop 1st consumer after getting any exception and what is the good way of fetching that particular failed query from backup log (consider lacs of queries, am thinking of using rolling appender log for multi log files). 我知道我必须从我的第二个使用者创建的备份中获取它,但是我必须在遇到任何异常后停止第一个使用者,从备份日志中获取特定失败查询的好方法是什么(考虑到查询的问题,我在想对多个日志文件使用滚动附加程序日志的说明)。 Thanks for patiently understanding my problem and please suggest a good way of achieving this issue. 感谢您耐心理解我的问题,并提出解决此问题的好方法。

try to categorize the failures that might occur on the consumer side. 尝试对在用户端可能发生的故障进行分类。 There might be 可能有

  • permanent errors (such as invalid SQL statements) and 永久错误(例如无效的SQL语句)和
  • temporary errors (network glitches, database server gone/restart,...) etc. 临时错误(网络故障,数据库服务器不可用/重新启动等)。

for temporary errors just retry the processing of the message (see spring's retry library). 对于临时错误,只需重试消息处理即可(请参见spring的重试库)。 messages that result into permanent errors might go into an invalid letter queue for further analysis/reporting (add the exception as header to the message before rerouting) 导致永久性错误的消息可能会进入invalid letter queue以进行进一步的分析/报告(在重新路由之前,将异常作为消息头添加到消息中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM