https://learn.microsoft.com/ en-us/azure/cosmos-db/how-to-develop-emulator?tabs=docker-linux%2Ccsharp&pivots=api-nosql
Я загрузил все необходимое программное обеспечение и успешно настроили работающий образ эмулятора Cosmos-DB с помощью Docker.

Теперь я использую Intellij и могу успешно запустить проект Java и Spring Boot для подключения к локальному эмулятору Azure Cosmos DB. Библиотека, которую я использую для подключения к эмулятору, следующая
Код: Выделить всё
implementation 'com.azure:azure-spring-data-cosmos:5.17.1'
Однако локально он жалуется на тайм-аут сокета со следующим сообщением об ошибке:
Код: Выделить всё
2024-10-11T16:30:32.352-04:00 WARN 23028 --- [tor-http-nio-17] c.a.c.implementation.ClientRetryPolicy : marking the endpoint https://172.17.0.2:8081/ as unavailable for read
2024-10-11T16:30:32.352-04:00 INFO 23028 --- [tor-http-nio-17] c.a.c.i.RxDocumentClientImpl : Getting database account endpoint from https://localhost:8081
2024-10-11T16:30:54.432-04:00 WARN 23028 --- [tor-http-nio-18] c.a.c.i.d.GatewayAddressCache : Network failure
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: getsockopt: /172.17.0.2:8081
Caused by: java.net.ConnectException: Connection timed out: getsockopt
at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:682) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:973) ~[na:na]
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:336) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:339) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.110.Final.jar:4.1.110.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994) ~[netty-common-4.1.110.Final.jar:4.1.110.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.110.Final.jar:4.1.110.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.110.Final.jar:4.1.110.Final]
at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]
Код: Выделить всё
@Bean
public CosmosClientBuilder getCosmosClientBuilder() {
final DirectConnectionConfig directConnectionConfig = new DirectConnectionConfig();
final GatewayConnectionConfig gatewayConnectionConfig = new GatewayConnectionConfig();
return new CosmosClientBuilder()
.endpoint("https://localhost:8081")
.credential(new ManagedIdentityCredentialBuilder()
.build())
.key("my primary key")
.directMode(directConnectionConfig, gatewayConnectionConfig)
.clientTelemetryConfig(
new CosmosClientTelemetryConfig()
.diagnosticsThresholds(
new CosmosDiagnosticsThresholds()
)
.diagnosticsHandler(CosmosDiagnosticsHandler.DEFAULT_LOGGING_HANDLER));
}
@Override
public CosmosConfig cosmosConfig() {
return CosmosConfig.builder()
.enableQueryMetrics(cosmosProperties.isQueryMetricsEnabled())
.enableIndexMetrics(cosmosProperties.isIndexMetricsEnabled())
.responseDiagnosticsProcessor(new ResponseDiagnosticsProcessorImplementation())
.build();
}
@Override
protected String getDatabaseName() {
return "Database Name";
}
private static class ResponseDiagnosticsProcessorImplementation implements ResponseDiagnosticsProcessor {
@Override
public void processResponseDiagnostics(@Nullable final ResponseDiagnostics responseDiagnostics) {
log.info("Response Diagnostics {}", responseDiagnostics);
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... timing-out
Мобильная версия