Skip to content

Commit

Permalink
Try to get the database name from the configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerard Klijs authored and gklijs committed Feb 2, 2024
1 parent cd514f5 commit 0d26585
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import org.axonframework.serialization.Serializer;
import org.axonframework.springboot.TokenStoreProperties;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

import static java.util.Objects.isNull;

/**
* Cosmos autoconfiguration class for Axon Framework application. Constructs the components which can be supplied by the
* {@code axon-cosmosdb}. This is just the token store ({@link CosmosTokenStore}).
Expand All @@ -33,15 +36,28 @@ public CosmosAutoConfiguration(
this.tokenStoreProperties = tokenStoreProperties;
}

@Value("${azure.cosmos.database:#{null}}")
private String dbName;

@Value("${spring.cloud.azure.cosmos.database:#{null}}")
private String cloudDbName;

@Bean("tokenStore")
@ConditionalOnMissingBean(TokenStore.class)
public TokenStore tokenStore(
@Qualifier(value = "azureCosmosAsyncClient") CosmosAsyncClient client,
Serializer serializer
) {
String databaseName = "axon";
if (!isNull(dbName)) {
databaseName = dbName;
} else if (!isNull(cloudDbName)) {
databaseName = cloudDbName;
}
return CosmosTokenStore.builder()
.client(client)
.serializer(serializer)
.databaseName(databaseName)
.claimTimeout(tokenStoreProperties.getClaimTimeout())
.build();
}
Expand Down

0 comments on commit 0d26585

Please sign in to comment.