NATS hosting integration
이 콘텐츠는 아직 번역되지 않았습니다.
To get started with the Aspire NATS hosting integration, install the Aspire.Hosting.Nats NuGet package in the app host project.
aspire add natsAspire CLI는 대화형입니다. 프롬프트 시 알맞은 검색 결과 선택:
Select an integration to add:
> nats (Aspire.Hosting.Nats)> Other results listed as selectable options...#:package Aspire.Hosting.Nats@*<PackageReference Include="Aspire.Hosting.Nats" Version="*" />Add NATS resource
Section titled “Add NATS resource”In your app host project, register and consume a NATS server integration using the AddNats extension method to add the NATS server resource to the builder:
var builder = DistributedApplication.CreateBuilder(args);
var nats = builder.AddNats("nats");
builder.AddProject<Projects.ExampleProject>() .WithReference(nats);
// After adding all resources, run the app...Add NATS with JetStream
Section titled “Add NATS with JetStream”To add NATS with JetStream enabled, which provides streaming capabilities, use the WithJetStream extension method:
var builder = DistributedApplication.CreateBuilder(args);
var nats = builder.AddNats("nats") .WithJetStream();
builder.AddProject<Projects.ExampleProject>() .WithReference(nats);Data persistence
Section titled “Data persistence”To add data volumes for persisting NATS data, call the WithDataVolume method:
var builder = DistributedApplication.CreateBuilder(args);
var nats = builder.AddNats("nats") .WithJetStream() .WithDataVolume();
builder.AddProject<Projects.ExampleProject>() .WithReference(nats);The data volume is used to persist the NATS data outside the lifecycle of the container.
For development scenarios, you may want to use bind mounts instead of data volumes. To add a data bind mount, call the WithDataBindMount method:
var builder = DistributedApplication.CreateBuilder(args);
var nats = builder.AddNats("nats") .WithJetStream() .WithDataBindMount(source: @"C:\Nats\Data");
builder.AddProject<Projects.ExampleProject>() .WithReference(nats);Add NATS with authentication
Section titled “Add NATS with authentication”To add NATS with username and password authentication, use the WithNatsUser and WithNatsPassword parameters:
var builder = DistributedApplication.CreateBuilder(args);
var user = builder.AddParameter("natsUser");var pass = builder.AddParameter("natsPass", secret: true);var nats = builder.AddNats("nats", userName: user, password: pass);
builder.AddProject<Projects.ExampleProject>() .WithReference(nats);