使用Spring Cloud Stream有状态地重试

时间:2018-10-25 15:57:09

标签: spring-cloud-stream

我已经实现了RetryListener,该监听使用Kafka侦听SCSt应用程序中的故障。我想知道是否有办法将其他信息传递给RetryContext,然后传递给重试的操作。

流量:

  1. 操作失败

  2. 调用
  3. RetryListener.onError(RetryContext上下文,RetryCallback回调,Throwable throwable)。 <---我想将其他信息传递给上下文

  4. 重试该操作<---我想将其他信息传递给重试(可能通过回调?)

我已经遍历了源代码,我知道可以将stateful boolean传递给RetryingMessageListenerAdapter,但是不确定如何将其传递给框架。

1 个答案:

答案 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 {