Skip to content

Conversation

@yhzdys
Copy link
Contributor

@yhzdys yhzdys commented Jan 16, 2026

Adds support for users to pre-set custom ExchangeId in HttpClientContext before request execution.

This enhancement enables better traceability and request correlation in distributed systems by allowing users to define their own exchange identifiers prior to request execution.

Comment on lines +463 to +480
/**
* @since 5.1
*/
public void setExchangeId(final String exchangeId) {
this.exchangeId = exchangeId;
}

/**
* @since 5.7
*/
public String setExchangeId(final Supplier<String> supplier) {
final String exchangeId = this.exchangeId; // avoid getfield opcode
if (exchangeId == null) {
return this.exchangeId = supplier.get();
} else {
return exchangeId;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks incoherent. I'd expect the client builders to simply take a Supplier<String> exchangeIdSupplier, which defaults to ExecSupport::getNextExchangeId. The context classes shouldn't need to know about what supplies the exchange IDs, they should just know the exchange ID for the particular exchange they represent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, there should be a documented contract for custom exchange ID suppliers, i.e. they must return a unique, non-null, non-blank string every time they are called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I'll refactor the implementation.

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