# aspire-apollo **Repository Path**: ymjake/aspire-apollo ## Basic Information - **Project Name**: aspire-apollo - **Description**: Aspire Apollo扩展包 - **Primary Language**: C# - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-12-31 - **Last Updated**: 2026-04-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: apollo, aspire ## README # Aspire Apollo libraries Two NuGet packages to run Apollo Configuration Center with .NET Aspire and consume it from your services. ## Packages - `YMJake.Aspire.Hosting.Apollo`: AppHost extensions to start Apollo (configservice, adminservice, portal) plus MySQL with bundled init SQL. - `YMJake.Aspire.Hosting.Apollo.QuickStart`: AppHost extensions to start Apollo quick-start (single container) plus MySQL. - `YMJake.Aspire.Apollo.Configuration`: Application-side extensions to load Apollo config, tracing, and health checks. ## Why database-discovery mode? Both hosting packages run Apollo in `database-discovery` mode (`SPRING_PROFILES_ACTIVE=github,database-discovery`). In standard Eureka-based discovery, ConfigService and AdminService register themselves with a host:port that must be reachable by other services. Under Aspire, container ports are proxied and assigned randomly at startup, so a fixed registration address cannot be guaranteed. Database-discovery replaces Eureka with direct MySQL polling, eliminating the dependency on fixed ports and making Apollo work correctly out of the box in Aspire's dynamic port environment. ## Quick start ### AppHost (full deployment) ```csharp using Aspire.Hosting.Apollo; var builder = DistributedApplication.CreateBuilder(args); var apollo = builder.AddApollo("apollo") // Persist MySQL data across restarts .WithMySqlDataBindMount("../.containers/apollo-db") // Set Apollo environment and configure portal meta address .WithEnv("DEV") // Mount log output for all three services (optional) .WithLogBindMount("../.containers/apollo-logs") // Tune JVM heap for local development (optional) .WithJvmArgs( configServiceArgs: "-Xms256m -Xmx512m", adminServiceArgs: "-Xms256m -Xmx512m", portalArgs: "-Xms256m -Xmx512m"); // Optional: custom MySQL password // var dbPassword = builder.AddParameter("apollo-db-password", "apollo", secret: true); // apollo = apollo.WithMySqlPassword(dbPassword); builder.AddProject("api") .WithReference(apollo); builder.Build().Run(); ``` ### AppHost (quick-start image) ```csharp using Aspire.Hosting.Apollo.QuickStart; var builder = DistributedApplication.CreateBuilder(args); var apollo = builder.AddApolloQuickStart("apollo") .WithMySqlDataBindMount("../.containers/apollo-db"); // Optional: custom MySQL password // var dbPassword = builder.AddParameter("apollo-db-password", "apollo", secret: true); // apollo = apollo.WithMySqlPassword(dbPassword); builder.AddProject("api") .WithReference(apollo); builder.Build().Run(); ``` ### App (consumer) `appsettings.Development.json` ```json { "Aspire": { "Apollo": { "apollo": { "AppId": "demo-app", "Cluster": "default", "Namespaces": ["application"], "Env": "DEV", "TimeoutMs": 5000, "RefreshIntervalMs": 30000 } } } } ``` Or use a connection string: ```json { "ConnectionStrings": { "apollo": "AppId=demo-app;Cluster=default;Namespaces=application;Env=DEV;TimeoutMs=5000;RefreshIntervalMs=30000" } } ``` `Program.cs` ```csharp builder.AddApolloConfiguration("apollo"); ``` `WithReference(apollo)` in the AppHost automatically injects `ConnectionStrings__apollo=Server=http://...`, so the `Server` address is resolved dynamically and does not need to be set manually. ## Extension methods ### `YMJake.Aspire.Hosting.Apollo` | Method | Description | |---|---| | `WithMySqlDataBindMount(path?)` | Persists MySQL data to a host directory | | `WithMySqlPassword(parameter)` | Sets a custom MySQL root password | | `WithEnv(env)` | Sets `APOLLO_PORTAL_ENVS` and `{ENV}_META` on the portal | | `WithLogBindMount(path?)` | Mounts `/opt/logs` for configservice, adminservice, and portal | | `WithJvmArgs(configServiceArgs?, adminServiceArgs?, portalArgs?)` | Sets `JAVA_OPTS` per service for JVM tuning | ### `YMJake.Aspire.Hosting.Apollo.QuickStart` | Method | Description | |---|---| | `WithMySqlDataBindMount(path?)` | Persists MySQL data to a host directory | | `WithMysqlPassword(parameter)` | Sets a custom MySQL root password | ## Notes - MySQL init scripts are packaged automatically; no extra setup needed. - `WithEnv(...)` is required for the full deployment package to configure `APOLLO_PORTAL_ENVS` and the meta server address. - `WithMySqlDataBindMount(...)` is recommended to persist MySQL data across restarts. - Apollo quick-start uses fixed internal ports (8080/8070/8090); host port customization is not supported.