Forum Discussion

TomLeub's avatar
TomLeub
Copper Contributor
Jan 24, 2025

Aspire with RabbitMQ unhealthy state

Hi,

First of all, I don't know if this is a good place to ask this question but it seems that there is no place to ask this on a dedicated Aspire hub.

I have a warning that i would like to get rid of on my RabbitMQ container.
I don't understand why it is always on status "Running (Unhealthy)".
I need to check that this container is healthy in order to start my 2 api services, otherwise they are not starting.

Here are the versions:

- Aspire.Host: v9.0.0
- RabbitMQ.Client: 7.0.0

Here is the log of the unhealthy reason:
System.TypeLoadException: Could not load type 'RabbitMQ.Client.IModel' from assembly 'RabbitMQ.Client, Version=7.0.0.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce'.**
**at HealthChecks.RabbitMQ.RabbitMQHealthCheck.CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken)**
**at Microsoft.Extensions.Diagnostics.HealthChecks.DefaultHealthCheckService.RunCheckAsync(HealthCheckRegistration registration, CancellationToken cancellationToken)

Here is the code of my Program.cs of the Aspire Host project:


var builder = DistributedApplication.CreateBuilder(args);

// Configure SQL Server with existing instance
var sqlServer = builder
    .AddSqlServer("coffee-sqlserver")
    .WithImageTag("latest")
    .WithLifetime(ContainerLifetime.Persistent)
    .WithDataVolume()
    .WithHttpEndpoint(port: 7000, targetPort: 1433) // Assuming 1433 is the default SQL Server port
    .AddDatabase("coffee-sqldb"); // Use existing database

// Configure PostgreSQL with existing instance
var postgres = builder
    .AddPostgres("coffee-order-postgresql")
    .WithImageTag("latest")
    .WithLifetime(ContainerLifetime.Persistent)
    .WithDataVolume()
    .WithHttpEndpoint(port: 7001, targetPort: 5432)
    .WithPgAdmin(); // Assuming 5432 is the default PostGreSQL port

// Connect to existing PostGreSQL databases
var postgresAdminDb = postgres.AddDatabase("coffee-admin-postgresdb");
var postgresDb = postgres.AddDatabase("coffee-order-postgresdb");

var migration = builder.AddProject<Projects.CoffeeShop_MigrationService>("migration")
    .WithReference(sqlServer)
    .WithReference(postgresDb)
    .WithReference(postgresAdminDb)
    .WaitFor(postgres)
    .WaitFor(postgresAdminDb)
    .WaitFor(postgresDb);

var rabbitUser = builder.AddParameter("username", true);
var rabbitPass = builder.AddParameter("password", true);

// Configure RabbitMQ with existing instance
var rabbitBroker = builder
    .AddRabbitMQ("coffee-rabbitmq", rabbitUser, rabbitPass)
    .WithImageTag("4.0.5")
    .WithLifetime(ContainerLifetime.Persistent)
    .WithHttpEndpoint(port: 7002, targetPort: 15672)
    .WithHttpsEndpoint(port: 8002, targetPort: 15672)
    //.WithEnvironment("RABBITMQ_DEFAULT_USER", "admin")
    //.WithEnvironment("RABBITMQ_DEFAULT_PASS", "password")
    .WithManagementPlugin();

// Configure Redis with existing instance
var cache = builder
    .AddRedis("coffee-redis")
    .WithImageTag("latest")
    .WithRedisInsight()
    .WithDataVolume();

// Configure the Admin Service
var adminService = builder.AddProject<Projects.CoffeeShop_AdminService>("adminservice")
    .WithHttpEndpoint(port:7004)
    .WithHttpsEndpoint(port: 8000)
    .WithReference(cache)
    .WithReference(migration)
    .WithReference(postgresAdminDb)
    .WithReference(rabbitBroker)
    .WaitFor(migration)
    .WaitFor(rabbitBroker);

// Configure the Order Service
var orderService = builder.AddProject<Projects.CoffeeShop_OrderService>("orderservice")
    .WithHttpEndpoint(port:7003)
    .WithHttpsEndpoint(port: 8001)
    .WithReference(cache)
    .WithReference(postgresDb)
    .WithReference(sqlServer)
    .WithReference(migration)
    .WithReference(rabbitBroker)
    .WaitFor(migration)
    .WaitFor(rabbitBroker);

// Configure the Angular Frontend
builder
    .AddNpmApp("frontend-angular", "../CoffeeShop.FrontEnd")
    .WithHttpEndpoint(port: 7005, env: "PORT")
    .WithReference(adminService)
    .WithReference(orderService)
    .WaitFor(adminService)
    .WaitFor(orderService)
    .WithExternalHttpEndpoints()
    .PublishAsDockerFile(); // This publishes the frontend as a Dockerfile

// Build and run the application
await builder.Build().RunAsync();

If someone have a tip to fix it, it would be awesome, Thanks !

P.S: I need to keep the RabbitMQ.Client in version 7.0.0, but I tried to downgrade to version 6.8.X and it won't work, maybe I have to use MassTransit ?

No RepliesBe the first to reply

Resources