Skip to content

Conversation

AlixBa
Copy link

@AlixBa AlixBa commented Jun 8, 2025

Allows custom wrapper to overload requestInternal MessageHandler.


Hello,

So this is a naive proposal, but I'd like to know if we could find something around this. I've been working on OTel for NATS recently and I noticed a behavior on the java agent that I can not reproduce on the library.

If I instrument MessageHandler on the agent to create both receive and process spans on onMessage, I see that for a request, I have the following sequence/spans:

  1. producer publish (subject:sub, replyTo: _INBOX.x)
  2. consumer receive (subject: sub)
  3. consumer process (subject: sub)
  4. consumer publish (subject: _INBOX.x)
  5. producer receive (subject: _INBOX.x)
  6. producer process (subject: _INBOX.x)

Which is a very good thing to troubleshoot server latencies between 4-5.

On the other hand, not using the agent, I can not overload the dispatcher created since it's not exposed anywhere. This little change reflects what could be done to have a better observability (I don't like the cast, though).

Thanks

Allows custom wrapper to overload requestInternal MessageHandler
@scottf
Copy link
Contributor

scottf commented Jun 10, 2025

@AlixBa
In Connection Options you can set the DispatcherFactory

public Builder dispatcherFactory(DispatcherFactory dispatcherFactory)

There is a real use example here: https://github.com/nats-io/nats-java-vertx-client/tree/main/src/main/java/io/nats/client/impl

@scottf scottf closed this Jun 10, 2025
@AlixBa
Copy link
Author

AlixBa commented Jun 12, 2025

I'll have a look, thanks for the hint, I totally missed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants