NatsAkka.Core 1.1.4

dotnet add package NatsAkka.Core --version 1.1.4
                    
NuGet\Install-Package NatsAkka.Core -Version 1.1.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NatsAkka.Core" Version="1.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NatsAkka.Core" Version="1.1.4" />
                    
Directory.Packages.props
<PackageReference Include="NatsAkka.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NatsAkka.Core --version 1.1.4
                    
#r "nuget: NatsAkka.Core, 1.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NatsAkka.Core@1.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NatsAkka.Core&version=1.1.4
                    
Install as a Cake Addin
#tool nuget:?package=NatsAkka.Core&version=1.1.4
                    
Install as a Cake Tool

通讯组件:https://github.com/nats-io/nats-server

appsettings.json中配置地址:
  "Nats": {
  "Url": "nats://127.0.0.1:4222",
  "DeviceName": "test",
  "DeviceDescription": "test模块"
},

依赖注入
services.AddSingleton<NatsClientFactory>();
var natsUrl = configuration["Nats:Url"];
var deviceName = configuration["Nats:DeviceName"];
// 注册IConnection为单例
services.AddSingleton<IConnection>(sp =>
{
    var logger = sp.GetRequiredService<ILogger<Program>>();
    var factory = sp.GetRequiredService<NatsClientFactory>();
    //如果为true则等待连接成功后再返回连接对象
    var connection = factory.CreateClient(natsUrl, deviceName, true); 
    return connection;
});

获取对象:
public class CarBusiness : NatsTopicManager
{
   private readonly IConnection _connection; 
   public Business(IConnection connection) : base(connection)
   {
       _connection = connection; 
       BeginReceiveMsg();
   }
  private void BeginReceiveMsg()
  { 
        //sub
        NatsSub<MessageTest1>(msg =>
        {
             
        });

        //Pub
        _connection.Publish(new MessageTest1());

        //Response
        NatsSubRequest<MessagesRequest1>((nats, msg) =>
         {
             try
             {
                 nats.Responsed(new MessagesRequest1Result());
             }
             catch (Exception ex)
             {
                  
             }
         });

         //Request,默认超时5000ms
        try
        {
           MessagesRequest1Result result = _connection.Request<MessagesRequest1, MessagesRequest1Result>(new MessagesRequest1());
        }
        catch (Exception ex)
        {
                  
        }
       
        
  }
 }

 
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.4 219 1/5/2026
1.1.3 120 1/5/2026
1.1.2 187 10/9/2025