DotNetCore.CAP.Extensions
1.1.0
dotnet add package DotNetCore.CAP.Extensions --version 1.1.0
NuGet\Install-Package DotNetCore.CAP.Extensions -Version 1.1.0
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="DotNetCore.CAP.Extensions" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetCore.CAP.Extensions --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: DotNetCore.CAP.Extensions, 1.1.0"
#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.
// Install DotNetCore.CAP.Extensions as a Cake Addin
#addin nuget:?package=DotNetCore.CAP.Extensions&version=1.1.0
// Install DotNetCore.CAP.Extensions as a Cake Tool
#tool nuget:?package=DotNetCore.CAP.Extensions&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
DotNetCore.CAP.Extensions
DotNetCore.CAP.Extensions 对 DotNetCore.CAP 做了扩展,使用传统的事件发布的写法,并且与 CAP 原来的写法相兼容
配置
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<StockCountChangeHandler>();
services.AddTransient<StockCountChangeCallbackHandler>();
services.AddCapExt(options =>
{
options.UseInMemoryStorage();
options.UseInMemoryMessageQueue();
});
}
定义两个 Cto
public class StockCountChangeCallbackCto
{
public bool Success { get; set; }
public string Message { get; set; }
}
public class StockCountChangeCto : IEventCallback<StockCountChangeCallbackCto>
{
public long OrderId { get; set; }
public int StockCount { get; set; }
}
Controller 定义发布信息 Action
[HttpGet]
public async Task<string> Get()
{
_logger.LogInformation("发布消息成功");
await _distributedEventBus.PublishAsync(new StockCountChangeCto
{
OrderId = 9898,
StockCount = 68
});
return "OK";
}
最后定义 EventHandler
public class StockCountChangeHandler : DistributedEventHandler<StockCountChangeCto, StockCountChangeCallbackCto>
{
private ILogger<StockCountChangeHandler> _logger;
public StockCountChangeHandler(ILogger<StockCountChangeHandler> logger)
{
_logger = logger;
}
public override Task<StockCountChangeCallbackCto> HandleEventAsync(StockCountChangeCto eventData, [FromCap] CapHeader headers)
{
return Task.FromResult(new StockCountChangeCallbackCto
{
Success = true,
Message = "库存更新成功"
});
}
}
public class StockCountChangeCallbackHandler : DistributedEventHandler<StockCountChangeCallbackCto>
{
private ILogger<StockCountChangeCallbackHandler> _logger;
public StockCountChangeCallbackHandler(ILogger<StockCountChangeCallbackHandler> logger)
{
_logger = logger;
}
public override Task HandleEventAsync(StockCountChangeCallbackCto eventData, [FromCap] CapHeader headers)
{
_logger.LogInformation(JsonSerializer.Serialize(eventData));
return Task.CompletedTask;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- DotNetCore.CAP (>= 5.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.