如何判断连接 RabbitMQ 消费者的服务器是否宕机?

huangapple go评论83阅读模式
英文:

How do I find out that the server with the rabbitmq consumer is down?

问题

我有一个生产者服务器和一个消费者服务器。生产者服务器将时间发送到RabbitMQ队列。消费者获取时间并将其放入ScheduledExecutorService池中。在指定的时间,消费者完成任务。我担心我的消费者会崩溃,导致数据丢失。因此,我需要实时了解我的消费者服务器何时会崩溃。但我没有找到如何实现这一点。请告诉我如何做到这一点。

英文:

I have a producer server and a consumer server. The producer server sends the time to the rabbitmq queue. The consumer gets the time and puts it in the ScheduledExecutorService pool. At the specified time, the consumer completes the task. I am afraid that my consumer will fall and I will lose data. So I need to know in real time when my consumer server will crash. But I didn't find how to implement it. Please tell me how to do this?

答案1

得分: 1

你可以使用众多可用的服务来监控你的服务器,并在其无响应时进行报告。举例来说,你可以使用 https://uptimerobot.com/ 并在你的服务上公开一个简单的HTTP端点,然后在该端点不可用时进行报告。还有许多其他综合性的监控服务可供选择,如:datadog、monitis、new relic等等。或者,你可以建立自己的监控系统,让另一台服务器定期检查你的消费服务器上的HTTP端点或其他内容,如果不可用就通知你。

话虽如此,我建议你改变你的消费者以避免数据丢失,如果它崩溃了,因为你正在为你的消费者创建定期任务,我建议你看看Quartz调度器,并使用它来安排和处理你的任务,而不是使用自定义的解决方案。如果使用JDBCJobStore等持久存储,Quartz将确保即使发生故障,你的任务也会继续运行。详细信息请参阅:http://www.quartz-scheduler.org/overview/

英文:

You could use one of the many available services to monitor your server and report if it was unresponsive. As an example, you could use https://uptimerobot.com/ and expose a simple HTTP endpoint on your service then report when that becomes unavailable. There are MANY other comprehensive monitoring services available like: datadog, monitis, new relic etc. Alternatively, you could build your own by having another server which periodically checks that an HTTP endpoint or whatever is available on your consumer server and notifies you if it isn't.

Having said that, I would recommend changing your consumer to avoid data loss if it were to crash since you're creating scheduled tasks on your consumer, I suggest you have a look at Quartz scheduler and use that to schedule and process your jobs rather than using a custom-built solution. Quartz will ensure that your jobs get run even after a failure if you use a persistent store like the JDBCJobStore. http://www.quartz-scheduler.org/overview/

huangapple
  • 本文由 发表于 2020年10月21日 01:27:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/64450402.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定