环境:
- 部署在 Kubernetes 上的 ActiveMQ
- 使用 openwire 的生产者 Java 应用程序
- 订阅者 Python 和 C 客户端使用 MQTT
问题陈述:
生产者每秒钟在主题上发送消息,订阅者相应地接收它。
但有时一天一次或三次订阅者停止接收消息大约 4 到 8 秒,然后客户端在 1 秒内批量接收所有丢失的消息。
我在 ActiveMQ 中启用了调试日志,但找不到任何异常/错误或警告
以下是客户端日志
2020-08-26 07:13:18,852 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:19,765 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:20,829 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:21,784 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
**Here its 5 seconds gap**
2020-08-26 07:13:26,831 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:28,745 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:29,905 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:30,917 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:31,484 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
**Three seconds Gap**
2020-08-26 07:13:34,221 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:34,881 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:37,450 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:38,078 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
**Below Can be seen all missing messages received within 1 seconds**
2020-08-26 07:13:40,391 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:40,422 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:40,423 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:40,423 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:40,423 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:40,423 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:40,423 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:40,456 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:40,456 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:40,962 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:43,400 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:43,475 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:44,431 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:45,139 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:46,074 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
2020-08-26 07:13:46,787 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'App/status'
虽然没有消息丢失,但我的应用程序需要在几秒钟内更新,奇怪的是这在 24 小时内随机发生两次或三次。
Update1: 经过大量优化和重构后,我终于找到了根本原因
发布者假设每 12 毫秒后发送一次频率状态,但从 13:28:08.132 到 13:28:08.174 它没有发送状态,然后在一条消息中发送所有先前丢失的信息。
代理到客户端日志 在下面的日志中,我们可以看到客户端在第 175、176、176、177、181 毫秒时收到状态。客户对此很敏感,并希望每 12 毫秒后收到一条消息,而不是一次性发送所有消息
2020-09-27 13:28:08,120 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'PKGCTRL/1/status/frequency', ... (49 bytes)
2020-09-27 13:28:08,134 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'PKGCTRL/1/status/frequency', ... (49 bytes)
2020-09-27 13:28:08,175 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'PKGCTRL/1/status/frequency', ... (49 bytes)
2020-09-27 13:28:08,176 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'PKGCTRL/1/status/frequency', ... (49 bytes)
2020-09-27 13:28:08,176 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'PKGCTRL/1/status/frequency', ... (49 bytes)
2020-09-27 13:28:08,177 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'PKGCTRL/1/status/frequency', ... (49 bytes)
2020-09-27 13:28:08,181 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'PKGCTRL/1/status/frequency', ... (49 bytes)
2020-09-27 13:28:08,188 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'PKGCTRL/1/status/frequency', ... (49 bytes)
2020-09-27 13:28:08,200 - DEBUG - Received PUBLISH (d0, q0, r0, m0), 'PKGCTRL/1/status/frequency', ... (49 bytes)