Skip to content

Support for NATS Cluster Configuration in Aspire.Hosting.AppHost #7563

Open
@honeyhead

Description

@honeyhead

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I'm trying to set up a NATS cluster within Aspire.Hosting.AppHost, but I found it difficult to configure clustering properly.

Currently, I can create multiple NATS instances like this

var nats = builder.AddNats("nats", 4584).WithJetStream();
var nats2 = builder.AddNats("nats2", 4585).WithJetStream();
var nats3 = builder.AddNats("nats3", 4586).WithJetStream();

builder.AddProject<Projects.WebApplication1>("webapplication1")
    .WithReference(nats)
    .WithReference(nats2)
    .WithReference(nats3);

However, setting up clustering between these instances is challenging. I would need to configure nats-server.conf manually or set up clustering via custom configuration, which is not straightforward.

Describe the solution you'd like

It would be great if Aspire.Hosting.AppHost could provide an easy way to set up NATS clustering through a built-in method, such as:

builder.AddNatsCluster("nats-cluster", new[] { ("nats", 4584), ("nats2", 4585), ("nats3", 4586) }).WithJetStream();

This might not work as expected since Aspire doesn’t work like this.
However, I would love to see a way to configure a NATS cluster similar to how WithJetStream() is provided.

Ideally, nats, nats2, and nats3 should be internally connected or be able to establish network connections with external NATS instances.

I know that the NATS client can be configured using JSON, but I'm not very familiar with how this works in hosting scenarios.

One possible approach might be to create a nats-server.conf file within AppHost and mount it, but this seems too complex for me.

If adding this feature is too difficult, could you guide me on how to achieve this manually?

Thanks in advance! 🚀

Additional context

NATS is actually well known compared to other technologies, but it works well with aspire compared to the scalability that is limited to SignalR. I'd like to have easier clusters, leaf nodes, and superclusters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-integrationsIssues pertaining to Aspire Integrations packagesnats

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions