Azure.Messaging.WebPubSub 1.0.0 Prefix Reserved

Install-Package Azure.Messaging.WebPubSub -Version 1.0.0
dotnet add package Azure.Messaging.WebPubSub --version 1.0.0
<PackageReference Include="Azure.Messaging.WebPubSub" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Azure.Messaging.WebPubSub --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Azure.Messaging.WebPubSub, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Azure.Messaging.WebPubSub as a Cake Addin
#addin nuget:?package=Azure.Messaging.WebPubSub&version=1.0.0

// Install Azure.Messaging.WebPubSub as a Cake Tool
#tool nuget:?package=Azure.Messaging.WebPubSub&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Azure Web PubSub service client library for .NET

Azure Web PubSub Service is an Azure-managed service that helps developers easily build web applications with real-time features and publish-subscribe pattern. Any scenario that requires real-time publish-subscribe messaging between server and clients or among clients can use Azure Web PubSub service. Traditional real-time features that often require polling from server or submitting HTTP requests can also use Azure Web PubSub service.

You can use this library in your app server side to manage the WebSocket client connections, as shown in below diagram:

overflow

Use this library to:

  • Send messages to hubs and groups.
  • Send messages to particular users and connections.
  • Organize users and connections into groups.
  • Close connections
  • Grant, revoke, and check permissions for an existing connection

Details about the terms used here are described in Key concepts section.

Source code | Package | API reference documentation | Product documentation | Samples

Getting started

Install the package

Install the client library from NuGet:

dotnet add package Azure.Messaging.WebPubSub --prerelease

Prerequisites

Create and authenticate a WebPubSubServiceClient

In order to interact with the service, you'll need to create an instance of the WebPubSubServiceClient class. To make this possible, you'll need the connection string or a key, which you can access in the Azure portal.

var serviceClient = new WebPubSubServiceClient(new Uri(endpoint), "some_hub", new AzureKeyCredential(key));

Key concepts

Connection

A connection, also known as a client or a client connection, represents an individual WebSocket connection connected to the Web PubSub service. When successfully connected, a unique connection ID is assigned to this connection by the Web PubSub service.

Hub

A hub is a logical concept for a set of client connections. Usually you use one hub for one purpose, for example, a chat hub, or a notification hub. When a client connection is created, it connects to a hub, and during its lifetime, it belongs to that hub. Different applications can share one Azure Web PubSub service by using different hub names.

Group

A group is a subset of connections to the hub. You can add a client connection to a group, or remove the client connection from the group, anytime you want. For example, when a client joins a chat room, or when a client leaves the chat room, this chat room can be considered to be a group. A client can join multiple groups, and a group can contain multiple clients.

User

Connections to Web PubSub can belong to one user. A user might have multiple connections, for example when a single user is connected across multiple devices or multiple browser tabs.

Message

When a client is connected, it can send messages to the upstream application, or receive messages from the upstream application, through the WebSocket connection.

Examples

Broadcast a text message to all clients

var serviceClient = new WebPubSubServiceClient(new Uri(endpoint), "some_hub", new AzureKeyCredential(key));

serviceClient.SendToAll("Hello World!");

Broadcast a JSON message to all clients

var serviceClient = new WebPubSubServiceClient(new Uri(endpoint), "some_hub", new AzureKeyCredential(key));

serviceClient.SendToAll(RequestContent.Create(
        new
        {
            Foo = "Hello World!",
            Bar = 42
        }),
        ContentType.ApplicationJson);

Broadcast a binary message to all clients

var serviceClient = new WebPubSubServiceClient(new Uri(endpoint), "some_hub", new AzureKeyCredential(key));

Stream stream = BinaryData.FromString("Hello World!").ToStream();
serviceClient.SendToAll(RequestContent.Create(stream), ContentType.ApplicationOctetStream);

Troubleshooting

Setting up console logging

You can also easily enable console logging if you want to dig deeper into the requests you're making against the service.

Next steps

Please take a look at the samples directory for detailed examples on how to use this library.

You can also find more samples here.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Azure.Messaging.WebPubSub:

Package Downloads
Blazor.Ninja.Client.Local

Blazor.Ninja Local Client Package

Microsoft.Azure.WebJobs.Extensions.WebPubSub

Azure Functions extension for the WebPubSub service

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 688 11/12/2021
1.0.0-beta.3 3,848 9/8/2021
1.0.0-beta.2 8,095 7/15/2021
1.0.0-beta.1 14,569 4/26/2021