AsyncApiWebSockets 1.1.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package AsyncApiWebSockets --version 1.1.0
NuGet\Install-Package AsyncApiWebSockets -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="AsyncApiWebSockets" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AsyncApiWebSockets --version 1.1.0
#r "nuget: AsyncApiWebSockets, 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 AsyncApiWebSockets as a Cake Addin
#addin nuget:?package=AsyncApiWebSockets&version=1.1.0

// Install AsyncApiWebSockets as a Cake Tool
#tool nuget:?package=AsyncApiWebSockets&version=1.1.0

AsyncAPI WebSockets

<img src=".logos/asyncapi-net-core.png" width="200" />  alternate text is missing from this package README image Codacy Badge

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 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.1 is compatible. 
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