Spring integration 在spring集成中使用服务激活器轮询器,如何在线程池中传递MCD(slf4j)上下文
有谁能建议我如何将MCD上下文传递给服务serviceName的方法吗?答案是对将在该TaskExecutor上执行的Runnable进行解码 互联网上有很多关于此事的文章: 此外,Spring Security还提供了一些解决方案,用于将SecurityContext从一个线程传播到另一个线程: 我建议您从这些链接中获得一些想法,并使用ThreadPoolTaskExecutor中现有的API: 因此,您的装饰程序应该有如下代码:Spring integration 在spring集成中使用服务激活器轮询器,如何在线程池中传递MCD(slf4j)上下文,spring-integration,slf4j,Spring Integration,Slf4j,有谁能建议我如何将MCD上下文传递给服务serviceName的方法吗?答案是对将在该TaskExecutor上执行的Runnable进行解码 互联网上有很多关于此事的文章: 此外,Spring Security还提供了一些解决方案,用于将SecurityContext从一个线程传播到另一个线程: 我建议您从这些链接中获得一些想法,并使用ThreadPoolTaskExecutor中现有的API: 因此,您的装饰程序应该有如下代码: /** * Specify a custom {@link
/**
* Specify a custom {@link TaskDecorator} to be applied to any {@link Runnable}
* about to be executed.
* <p>Note that such a decorator is not necessarily being applied to the
* user-supplied {@code Runnable}/{@code Callable} but rather to the actual
* execution callback (which may be a wrapper around the user-supplied task).
* <p>The primary use case is to set some execution context around the task's
* invocation, or to provide some monitoring/statistics for task execution.
* @since 4.3
*/
public void setTaskDecorator(TaskDecorator taskDecorator) {
/**
* Specify a custom {@link TaskDecorator} to be applied to any {@link Runnable}
* about to be executed.
* <p>Note that such a decorator is not necessarily being applied to the
* user-supplied {@code Runnable}/{@code Callable} but rather to the actual
* execution callback (which may be a wrapper around the user-supplied task).
* <p>The primary use case is to set some execution context around the task's
* invocation, or to provide some monitoring/statistics for task execution.
* @since 4.3
*/
public void setTaskDecorator(TaskDecorator taskDecorator) {
taskExecutor.setTaskDecorator(runnable -> {
Map<String, String> mdc = MDC.getCopyOfContextMap();
return () -> {
MDC.setContextMap(mdc);
runnable.run();
};
});