Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
provide MDC context map to submitted task
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan.Praetsch committed Apr 17, 2024
1 parent 145bec6 commit 78d439c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.8.0

* pass MDC context to workers

# 0.7.1

* adds the possibility to configure a handling in case of a `Throwable` in `ErrorHandlingStrategy`
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<artifactId>sqs-utils</artifactId>
<groupId>com.mercateo.sqs</groupId>
<name>sqs-utils</name>
<version>0.7.5-SNAPSHOT</version>
<version>0.8.0-SNAPSHOT</version>
<packaging>jar</packaging>

<description>Some utility classes for AWS SQS</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.mercateo.sqs.utils.visibility.VisibilityTimeoutExtenderFactory;

import java.time.Duration;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
Expand All @@ -28,6 +30,7 @@
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import org.slf4j.MDC;
import org.springframework.messaging.Message;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

Expand Down Expand Up @@ -79,7 +82,16 @@ public class LongRunningMessageHandler<I, O> {
this.awaitShutDown = awaitShutDown;
this.errorHandlingStrategy = errorHandlingStrategy;

messageProcessingExecutor = new ThreadPoolTaskExecutor();
messageProcessingExecutor = new ThreadPoolTaskExecutor() {
@Override
public Future<?> submit(Runnable task) {
Map<String, String> current = MDC.getCopyOfContextMap();
return super.submit(() -> {
MDC.setContextMap(current);
task.run();
});
}
};
messageProcessingExecutor.setCorePoolSize(numberOfThreads);
messageProcessingExecutor.setMaxPoolSize(numberOfThreads);
messageProcessingExecutor.setThreadNamePrefix(getClass().getSimpleName()+"-"+queue.getName().getId()+"-");
Expand Down

0 comments on commit 78d439c

Please sign in to comment.