microsoft / microsoft/aspire

Support for NATS Cluster Configuration in Aspire.Hosting.AppHost

Open
#7,563 1 comment 1 reaction 0 assignees View on GitHub
area-integrations nats
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] 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("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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.