我已经实现了RetryListener
,该监听使用Kafka侦听SCSt应用程序中的故障。我想知道是否有办法将其他信息传递给RetryContext,然后传递给重试的操作。
流量:
操作失败
RetryListener.onError(RetryContext上下文,RetryCallback回调,Throwable throwable)。 <---我想将其他信息传递给上下文
重试该操作<---我想将其他信息传递给重试(可能通过回调?)
我已经遍历了源代码,我知道可以将stateful
boolean
传递给RetryingMessageListenerAdapter
,但是不确定如何将其传递给框架。
答案 0 :(得分:0)
在侦听器线程上...
RetrySynchronizationManager.getContext().setAttribute("foo", "bar");
/**
* Global variable support for retry clients. Normally it is not necessary for
* clients to be aware of the surrounding environment because a
* {@link RetryCallback} can always use the context it is passed by the
* enclosing {@link RetryOperations}. But occasionally it might be helpful to
* have lower level access to the ongoing {@link RetryContext} so we provide a
* global accessor here. The mutator methods ({@link #clear()} and
* {@link #register(RetryContext)} should not be used except internally by
* {@link RetryOperations} implementations.
*
* @author Dave Syer
*
*/
public final class RetrySynchronizationManager {