From 54a2f5275d742b540f72c6202d7017da8f8e1877 Mon Sep 17 00:00:00 2001 From: hello Date: Thu, 18 Dec 2025 22:41:57 +0800 Subject: [PATCH] =?UTF-8?q?Aspire=2013.1=20=E6=96=B0=E7=89=B9=E6=80=A7?= =?UTF-8?q?=E4=B8=8E=20MCP=20=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .aspire/settings.json | 3 ++ Directory.Packages.props | 16 +++++----- .../Extensions/OpenApiConfigureOptions.cs | 30 +++++++++++++++---- src/HelloShop.ApiService/Program.cs | 6 ++++ .../DaprComponents/redis-lock.yaml | 2 ++ .../HelloShop.AppHost.csproj | 2 +- .../HelloShop.HybridApp.csproj | 4 +-- 7 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 .aspire/settings.json diff --git a/.aspire/settings.json b/.aspire/settings.json new file mode 100644 index 0000000..978c755 --- /dev/null +++ b/.aspire/settings.json @@ -0,0 +1,3 @@ +{ + "appHostPath": "../src/HelloShop.AppHost/HelloShop.AppHost.csproj" +} \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index 1590369..15d0163 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,14 +4,14 @@ true - - - - - - - - + + + + + + + + diff --git a/src/HelloShop.ApiService/Extensions/OpenApiConfigureOptions.cs b/src/HelloShop.ApiService/Extensions/OpenApiConfigureOptions.cs index 8c7cb94..311d10b 100644 --- a/src/HelloShop.ApiService/Extensions/OpenApiConfigureOptions.cs +++ b/src/HelloShop.ApiService/Extensions/OpenApiConfigureOptions.cs @@ -20,9 +20,12 @@ public class OpenApiConfigureOptions(IConfiguredServiceEndPointResolver serviceR UriBuilder uriBuilder = new(endPoint) { Path = "/openapi/v1.json" }; try - { + { HttpRequestMessage request = new(HttpMethod.Get, uriBuilder.Uri) { Version = new Version(2, 0) }; - HttpResponseMessage response = httpClient.SendAsync(request).GetAwaiter().GetResult(); + + using CancellationTokenSource cts = new(TimeSpan.FromSeconds(5)); + HttpResponseMessage response = httpClient.SendAsync(request, cts.Token).GetAwaiter().GetResult(); + if (response.IsSuccessStatusCode) { urlDescriptors.Add(new UrlDescriptor @@ -32,18 +35,35 @@ public class OpenApiConfigureOptions(IConfiguredServiceEndPointResolver serviceR }); break; } + else + { + if (logger.IsEnabled(LogLevel.Warning)) + { + logger.LogWarning("Failed to get swagger endpoint for {ServiceName} at {Endpoint}, Status: {StatusCode}", + serviceEndpoint.ServiceName, uriBuilder.Uri, response.StatusCode); + } + } + } + catch (OperationCanceledException) + { + if (logger.IsEnabled(LogLevel.Warning)) + { + logger.LogWarning("Timeout getting swagger endpoint for {ServiceName} at {Endpoint}", + serviceEndpoint.ServiceName, uriBuilder.Uri); + } } catch (Exception ex) { - if (logger.IsEnabled(LogLevel.Error)) + if (logger.IsEnabled(LogLevel.Warning)) { - logger.LogError(ex, "Failed to get swagger endpoint for {ServiceName}", serviceEndpoint.ServiceName); + logger.LogWarning(ex, "Failed to get swagger endpoint for {ServiceName} at {Endpoint}", + serviceEndpoint.ServiceName, uriBuilder.Uri); } } } } - options.ConfigObject.Urls = urlDescriptors; + options.ConfigObject.Urls = urlDescriptors; options.SwaggerEndpoint("/openapi/v1.json", "apiservice"); } } diff --git a/src/HelloShop.ApiService/Program.cs b/src/HelloShop.ApiService/Program.cs index bc0a262..794d905 100644 --- a/src/HelloShop.ApiService/Program.cs +++ b/src/HelloShop.ApiService/Program.cs @@ -25,6 +25,12 @@ builder.Services.AddReverseProxy() builder.Services.AddSingleton(); builder.Services.AddSingleton(); + +builder.Services.AddHttpClient(client => +{ + client.Timeout = TimeSpan.FromSeconds(30); +}); + builder.Services.AddTransient, OpenApiConfigureOptions>(); builder.Services.AddTransient(); diff --git a/src/HelloShop.AppHost/DaprComponents/redis-lock.yaml b/src/HelloShop.AppHost/DaprComponents/redis-lock.yaml index 9839bc6..2eada91 100644 --- a/src/HelloShop.AppHost/DaprComponents/redis-lock.yaml +++ b/src/HelloShop.AppHost/DaprComponents/redis-lock.yaml @@ -10,5 +10,7 @@ spec: value: "localhost:6379" - name: redisPassword value: "guest" + - name: enableTLS + value: "true" auth: secretStore: env-secretstore \ No newline at end of file diff --git a/src/HelloShop.AppHost/HelloShop.AppHost.csproj b/src/HelloShop.AppHost/HelloShop.AppHost.csproj index 5d122a8..cf1d02e 100644 --- a/src/HelloShop.AppHost/HelloShop.AppHost.csproj +++ b/src/HelloShop.AppHost/HelloShop.AppHost.csproj @@ -1,4 +1,4 @@ - + Exe net10.0 diff --git a/src/HelloShop.HybridApp/HelloShop.HybridApp.csproj b/src/HelloShop.HybridApp/HelloShop.HybridApp.csproj index a1120a4..39606aa 100644 --- a/src/HelloShop.HybridApp/HelloShop.HybridApp.csproj +++ b/src/HelloShop.HybridApp/HelloShop.HybridApp.csproj @@ -62,8 +62,8 @@ - - + +