AsyncApiWebSockets 1.1.0
dotnet add package AsyncApiWebSockets --version 1.1.0
NuGet\Install-Package AsyncApiWebSockets -Version 1.1.0
<PackageReference Include="AsyncApiWebSockets" Version="1.1.0" />
<PackageVersion Include="AsyncApiWebSockets" Version="1.1.0" />
<PackageReference Include="AsyncApiWebSockets" />
paket add AsyncApiWebSockets --version 1.1.0
#r "nuget: AsyncApiWebSockets, 1.1.0"
#addin nuget:?package=AsyncApiWebSockets&version=1.1.0
#tool nuget:?package=AsyncApiWebSockets&version=1.1.0
AsyncAPI WebSockets
<img src=".logos/asyncapi-net-core.png" width="200" />
Description
This .NET Core middleware provides functionality for WebSocket connections which are specified with AsyncAPI. It also handles the communication between the server-side channel and the client.
Usage
Install NuGet Package
dotnet add package AsyncApiWebSockets --version 1.1.0
Register in Startup.cs
Add to DI container via ConfigureServices()
services.AddAsyncApiWebSockets(options =>
{
options.AsyncApi = new AsyncApiDocument
{
Info = new Info("Async API", "1.0.0")
{
Description = "Description"
}
};
});
(For detailed information on options, please check KnstEventBus on GitHub)
Add to request pipeline via Configure()
app.UseAsyncApiWebSockets();
Add attributes to channel classes and derive from BaseChannel
[AsyncApi]
[Channel("HelloWorld")]
public class HelloWorldChannel : BaseChannel<PubHelloWorldObject, SubHelloWorldObject>
{
// This injection is necessary for WebSocket communication
public HelloWorldChannel(WebSocketHolder wsh) : base(wsh) { }
[Publish]
[Message(typeof(PubHelloWorldObject))]
public Task PublishAsync(PubHelloWorldObject o)
{
// Tasks when publishing a message
// Use return Task.FromResult for responding on the same WebSocket
}
[Subscribe]
[Message(typeof(SubHelloWorldObject))]
public Task SubscribeAsync()
{
// Tasks for sending messages to the clients
}
}
(For detailed information on attributes, please check KnstEventBus on GitHub)
Run the program and connect
Connect to your service via any programming language, you want to. The data exchange format is JSON.
Client-side messages
Now when you connect to ws{s}://{host}:{port}/{ChannelName}
all incoming messages will be proxied to the
channel and the Publish
-attributed method will be invoked with the received and deserialized JSON-object.
If your Publish
-attributed method returns any object, it will be serialized and sent to the same socket
from where the message was received.
Server-side messages
For server-side messages, please call the following method in your channel:
OnMessageToSend(this, msg);
When doing this, all clients which are connected to the channel, will receive the sent message.
Logging
The common ILogger
interface is supported by the middleware. If you have added logging to your project, you
will see any upcoming errors in the middleware. Please note that logging from the middleware can be configured
via appSettings.json
.
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. 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. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- KnstAsyncApi (>= 1.1.1)
- Microsoft.AspNetCore.WebSockets (>= 2.2.1)
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 |
---|