-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Milestone
Description
I have a use-case where I need to do ResponseContext.setResponse()
after performing request-reply and withing an Observation
scope.
So, to achieve that I have to do something like this:
RequestReplyReceiverContext context = new MyCtx();
return ObservationDoc.PROCESS.observation(this.observationConvention,
DefaultConvention.INSTANCE,
() -> context, this.observationRegistry)
.observe(() -> {
Message<?> reply = requestReply();
context.setResponse(reply);
return reply;
});
This way I have to be sure about an ObservationRegistry.NOOP
before calling this code.
With an Observation.observe(Function<C extends Observation.Context, T> function)
API it would look like this:
return ObservationDoc.PROCESS.observation(this.observationConvention,
DefaultConvention.INSTANCE,
() -> new MyCtx(), this.observationRegistry)
.observe((context) -> {
Message<?> reply = requestReply();
context.setResponse(reply);
return reply;
});
and no any extra if...else
around!