Optional io.micrometer:context-propagation (#8556)
For better performance by default it is better to not pull a `io.micrometer:context-propagation` a hard dependency. * Remove `io.micrometer:context-propagation` dependency management * It is pulled transitively by the `io.micrometer:micrometer-tracing-integration-test` in test scope * Rework all the `ContextSnapshot` usage in the reactive code to respective recommended `handle()` API in `Flux` and `Mono`
This commit is contained in:
@@ -20,7 +20,6 @@ import java.time.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import io.micrometer.context.ContextSnapshot;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.reactivestreams.Subscriber;
|
||||
import reactor.core.Disposable;
|
||||
@@ -112,19 +111,18 @@ public class FluxMessageChannel extends AbstractMessageChannel
|
||||
Flux.from(publisher)
|
||||
.delaySubscription(this.subscribedSignal.asFlux().filter(Boolean::booleanValue).next())
|
||||
.publishOn(this.scheduler)
|
||||
.transformDeferredContextual((flux, contextView) ->
|
||||
flux.doOnNext((message) -> {
|
||||
var scope = ContextSnapshot.setAllThreadLocalsFrom(contextView);
|
||||
try (scope) {
|
||||
if (!send(message)) {
|
||||
throw new MessageDeliveryException(message,
|
||||
"Failed to send message to channel '" + this);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.warn(ex, () -> "Error during processing event: " + message);
|
||||
}
|
||||
}))
|
||||
.handle((message, synchronousSink) -> {
|
||||
try {
|
||||
if (!send(message)) {
|
||||
logger.warn(new MessageDeliveryException(message,
|
||||
"Failed to send message to channel '" + this),
|
||||
"Message was not delivered");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.warn(ex, () -> "Error during processing event: " + message);
|
||||
}
|
||||
})
|
||||
.contextCapture()
|
||||
.subscribe());
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import io.micrometer.context.ContextSnapshot;
|
||||
import io.micrometer.observation.ObservationRegistry;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.reactivestreams.Subscriber;
|
||||
@@ -721,7 +720,7 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint
|
||||
throw new MessageMappingException("Cannot map to message: " + object, e);
|
||||
}
|
||||
|
||||
return Mono.deferContextual(contextView -> {
|
||||
return Mono.defer(() -> {
|
||||
Object originalReplyChannelHeader = requestMessage.getHeaders().getReplyChannel();
|
||||
Object originalErrorChannelHeader = requestMessage.getHeaders().getErrorChannel();
|
||||
|
||||
@@ -739,13 +738,13 @@ public abstract class MessagingGatewaySupport extends AbstractEndpoint
|
||||
.setErrorChannel(replyChan)
|
||||
.build();
|
||||
|
||||
var scope = ContextSnapshot.setAllThreadLocalsFrom(contextView);
|
||||
try (scope) {
|
||||
sendMessageForReactiveFlow(requestChannel, messageToSend);
|
||||
}
|
||||
|
||||
return buildReplyMono(requestMessage, replyChan.replyMono.asMono(), error,
|
||||
originalReplyChannelHeader, originalErrorChannelHeader);
|
||||
return Mono.just(messageToSend)
|
||||
.handle((message, synchronousSink) -> {
|
||||
sendMessageForReactiveFlow(requestChannel, message);
|
||||
synchronousSink.complete();
|
||||
})
|
||||
.then(buildReplyMono(requestMessage, replyChan.replyMono.asMono(), error,
|
||||
originalReplyChannelHeader, originalErrorChannelHeader));
|
||||
})
|
||||
.onErrorResume(t -> error ? Mono.error(t) : handleSendError(requestMessage, t));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user