Accessing Topics' Information at Runtime

从 2.9 版开始,可以通过注入提供的 DestinationTopicContainer bean 来访问有关主题链的运行时信息。此接口提供用于查找链中的下一个主题或某个主题的 DLT(如果已配置)的方法,以及主题名称、延迟和类型等有用的属性。

Since 2.9, you can access information regarding the topic chain at runtime by injecting the provided DestinationTopicContainer bean. This interface provides methods to look up the next topic in the chain or the DLT for a topic if configured, as well as useful properties such as the topic’s name, delay and type.

以一个现实的用例为例,您可以在解决了处理失败的原因(例如,错误/不一致的状态)后,使用此类信息让控制台应用程序将记录从 DLT 重新发送到链中的第一个重试主题。

As a real-world use-case example, you can use such information so a console application can resend a record from the DLT to the first retry topic in the chain after the cause of the failed processing, e.g. bug / inconsistent state, has been resolved.

DestinationTopicContainer#getNextDestinationTopicFor() 方法提供的 DestinationTopic 对应于输入主题中链中注册的下一个主题。消息将被转发到的实际主题可能会因异常分类、尝试次数或单一主题固定延迟策略等不同因素而异。如果您需要权衡这些因素,请使用 DestinationTopicResolver 接口。

The DestinationTopic provided by the DestinationTopicContainer#getNextDestinationTopicFor() method corresponds to the next topic registered in the chain for the input topic. The actual topic the message will be forwarded to may differ due to different factors such as exception classification, number of attempts or single-topic fixed-delay strategies. Use the DestinationTopicResolver interface if you need to weigh in these factors.