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

provide MDC context map to submitted task #21

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading