Quantcast
Channel: Active questions tagged propagation - Stack Overflow
Viewing all articles
Browse latest Browse all 52

Spring WebFlux and Context propgation

$
0
0

I have a Flux that is emitting messages received from the SocketServer. Part of the processing of those messages sometimes throws a exception exception (bad data), so I need to get the session id out of an object to respond to that SocketServer client.The message is processed in the listenToSocketServerReceivedMessages and handed of to processSocketServerMessage, and is working fine.

The spring beans look something like this:

@Component@Slf4jpublic class SocketServerEventNotificationHandler {     private final @NonNull Sinks.Many<SocketServerEventNotification> socketServerEventNotifications;     private final Sinks.EmitFailureHandler emitFailureHandler = (signalType, emitResult) -> emitResult             .equals(Sinks.EmitResult.FAIL_NON_SERIALIZED) ? true : false;     public SocketServerEventNotificationHandler() {          this.socketServerEventNotifications = Sinks.many().multicast().onBackpressureBuffer();     }     public Flux<SocketServerEventNotification> getSocketServerNotifications() {          return socketServerEventNotifications.asFlux()                  .contextWrite(context -> context.put("Key","asasas"));     }     public void emitSocketServerNotification(final SocketServerEventNotification socketServerEventNotification) {          log.debug("Emit socket server notification : {}", socketServerEventNotification);          socketServerEventNotifications.emitNext(socketServerEventNotification, emitFailureHandler);     }}

and

@Component@RequiredArgsConstructor@Slf4jpublic class SocketServerEventListener {     private final SocketServerEventNotificationHandler socketServerEventNotificationHandler;     private final SocketServerMessageReceiver socketServerMessageReceiver;     private final SockerServerMessageSender sockerServerMessageSender;     @PostConstruct     public void init() {          this.listenToSocketServerReceivedMessages()                  .subscribe(                          success -> log.debug("Success processing listenToSocketServerReceivedMessages"),                          err -> log.error("Error listenToSocketServerReceivedMessages : " + err)                  );     }     public Flux<String> listenToSocketServerReceivedMessages() {          return this.socketServerEventNotificationHandler.getSocketServerNotifications()                  .flatMap(message -> {                       log.debug("Received message to process for interviewId : {}", message.getInterviewId());                       var inboundSocketServerMessage = new InboundSocketServerMessage(message.getInterviewId(), LocalDateTime.now());                       return socketServerMessageReceiver.processSocketServerMessage(inboundSocketServerMessage);                  })                  .onErrorContinue((throwable, obj) -> {                       log.info("~~~~~ throwable : {} ; obj : {}", throwable, obj);                       Mono.deferContextual(ctx -> {                            ctx.size();                            return Mono.just(ctx);                       }).subscribe();                  })                  .flatMap(notification -> {                       log.info("~~~~~ Processed SocketServer event : [{}]", notification);                       return Mono.just(notification);                  });     }}

The message object after the .flatmap contains the interviewId that I'm after. However, the standard two objects in the .onErrorContinue do not help a lot. (might the mistaken).

I have tried to add another .flatmap to insert the message into the context, but it just is not visible in the error bit.

I'm a bit stuck now and have run out of ideas on how to get hold of that information.

Any pointers will be greatly appreciated.


Viewing all articles
Browse latest Browse all 52

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>