I am working with Azure cosmos DB (NoSQL API) and have set below configs for connection and creating Async client.
@Bean
public CosmosClientBuilder getCosmosClientBuilder() {
return new CosmosClientBuilder()
.endpoint(endpoint)
.key(key)
.consistencyLevel(ConsistencyLevel.SESSION)
.preferredRegions(List.of("Central US"));
}
@Bean
public CosmosAsyncDatabase cosmosAsyncDatabase() {
return getCosmosClientBuilder().buildAsyncClient().getDatabase(getDatabaseName());
}
Code where this config is used :
@Autowired
public StatusByIdLocationDaoImpl(CosmosAsyncDatabase cosmosAsyncDatabase) {
log.info("DATABASE : " + cosmosAsyncDatabase.getId());
this.cosmosAsyncContainer = cosmosAsyncDatabase.getContainer("status_test");
log.info("CONTAINER : : " + cosmosAsyncContainer.getId());
}
@Override
public Iterable<FeedResponse<Data>> getStatusEvents(Instant startTime, Instant endTime, String continueToken, int batchSize) {
CosmosQueryRequestOptions cosmosQueryRequestOptions = new CosmosQueryRequestOptions();
try {
log.info("CALLING THE DB");
return cosmosAsyncContainer.queryItems(query, cosmosQueryRequestOptions, Data.class).byPage(continueToken, batchSize).toIterable();
} catch (CosmosException cosmosException) {
log.error("Error occurred while fetch the status events : {}", cosmosException.getDiagnostics());
log.error("Error", cosmosException.fillInStackTrace());
return null;
}
}
Now when I am running the application in local, I works fine but when I am deploying the application k8s, I am getting below issue, where it starts the application and immediately closes (Shutdown) it.
I am not sure what is wrong with configuration as it is working on local.
I have also tried doing the same with repository pattern but getting same error as above
Here is the dependency used for cosmos:
implementation group: 'com.azure', name: 'azure-spring-data-cosmos', version: '3.30.0'