Skip to content

Commit

Permalink
Enabling v2 stack as the default for Event Hubs (#43725)
Browse files Browse the repository at this point in the history
* Enabling v2 stack as the default for Event Hubs

* Update V2StackSupport to enable v2 by default
  • Loading branch information
anuchandy authored Jan 8, 2025
1 parent 2cbcdf6 commit b5578fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
2 changes: 2 additions & 0 deletions sdk/eventhubs/azure-messaging-eventhubs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Features Added

Setting the v2 stack as the default. ([43725](https://github.com/Azure/azure-sdk-for-java/pull/43725))

### Breaking Changes

- Do not remove `x-opt-partition-key` message annotation when publishing events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ final class V2StackSupport {
private static final ConfigurationProperty<Boolean> V2_STACK_PROPERTY
= ConfigurationPropertyBuilder.ofBoolean(V2_STACK_KEY)
.environmentVariableName(V2_STACK_KEY)
.defaultValue(false)
.defaultValue(true)
.shared(true)
.build();
private final AtomicReference<Boolean> v2StackFlag = new AtomicReference<>();
Expand All @@ -62,7 +62,7 @@ final class V2StackSupport {
* @return true if the clients should use the v2 stack.
*/
boolean isV2StackEnabled(Configuration configuration) {
return isOptedIn(configuration, V2_STACK_PROPERTY, v2StackFlag);
return !isOptedOut(configuration, V2_STACK_PROPERTY, v2StackFlag);
}

/**
Expand Down Expand Up @@ -113,33 +113,6 @@ private boolean isOptedOut(Configuration configuration, ConfigurationProperty<Bo
return choiceFlag.get();
}

private boolean isOptedIn(Configuration configuration, ConfigurationProperty<Boolean> configProperty,
AtomicReference<Boolean> choiceFlag) {
final Boolean flag = choiceFlag.get();
if (flag != null) {
return flag;
}

final String propName = configProperty.getName();
final boolean isOptedIn;
if (configuration != null) {
isOptedIn = configuration.get(configProperty);
} else {
assert !CoreUtils.isNullOrEmpty(propName);
if (!CoreUtils.isNullOrEmpty(System.getenv(propName))) {
isOptedIn = "true".equalsIgnoreCase(System.getenv(propName));
} else if (!CoreUtils.isNullOrEmpty(System.getProperty(propName))) {
isOptedIn = "true".equalsIgnoreCase(System.getProperty(propName));
} else {
isOptedIn = false;
}
}
if (choiceFlag.compareAndSet(null, isOptedIn)) {
logger.verbose("Selected configuration {}={}", propName, isOptedIn);
}
return choiceFlag.get();
}

ReactorConnectionCache<EventHubReactorAmqpConnection> createConnectionCache(ConnectionOptions connectionOptions,
Supplier<String> eventHubNameSupplier, MessageSerializer serializer, Meter meter,
boolean useSessionChannelCache) {
Expand Down

0 comments on commit b5578fb

Please sign in to comment.