Skip to content

Commit 438ad43

Browse files
Adding WebPubSub Client Library (Azure#20597)
* Adding WebPubSub Client Library * update API file * fixed build warning * Update sdk/webpubsub/Azure.Messaging.WebPubSub/README.md dotnet add command now has --prerelease Co-authored-by: tg-msft <tg-msft@users.noreply.github.com> * Update sdk/webpubsub/Azure.Messaging.WebPubSub/README.md Removed namespace from AzureKeyCredential Co-authored-by: tg-msft <tg-msft@users.noreply.github.com> * Update sdk/webpubsub/Azure.Messaging.WebPubSub/README.md removed empty link from readme Co-authored-by: tg-msft <tg-msft@users.noreply.github.com> * Update sdk/webpubsub/Azure.Messaging.WebPubSub/README.md Co-authored-by: tg-msft <tg-msft@users.noreply.github.com> * Update sdk/webpubsub/Azure.Messaging.WebPubSub/README.md Co-authored-by: tg-msft <tg-msft@users.noreply.github.com> * Update sdk/webpubsub/Azure.Messaging.WebPubSub/README.md Co-authored-by: tg-msft <tg-msft@users.noreply.github.com> * Update sdk/webpubsub/Azure.Messaging.WebPubSub/src/WebPubSubServiceClient.cs Co-authored-by: tg-msft <tg-msft@users.noreply.github.com> * draft PR review comments * small batch of other PR comments * next batch of PR feedback * Update README.md * Update README.md * updated API file * Removing manual generated code changes Co-authored-by: tg-msft <tg-msft@users.noreply.github.com> Co-authored-by: tg-msft <Ted.Glaza@microsoft.com>
1 parent 3de98dc commit 438ad43

28 files changed

+4728
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29709.97
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Core.TestFramework", "..\..\core\Azure.Core.TestFramework\src\Azure.Core.TestFramework.csproj", "{8052009B-2126-44A3-88CD-4F3B17894C64}"
7+
EndProject
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Messaging.WebPubSub", "src\Azure.Messaging.WebPubSub.csproj", "{AF06AB51-3B39-4905-B7EA-CD7563DE5770}"
9+
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Messaging.WebPubSub.Tests", "tests\Azure.Messaging.WebPubSub.Tests.csproj", "{ADB00BD6-8FEE-4176-BE15-4F530F5C8F29}"
11+
EndProject
12+
Global
13+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
14+
Debug|Any CPU = Debug|Any CPU
15+
Release|Any CPU = Release|Any CPU
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{8052009B-2126-44A3-88CD-4F3B17894C64}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{8052009B-2126-44A3-88CD-4F3B17894C64}.Release|Any CPU.Build.0 = Release|Any CPU
22+
{AF06AB51-3B39-4905-B7EA-CD7563DE5770}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{AF06AB51-3B39-4905-B7EA-CD7563DE5770}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{AF06AB51-3B39-4905-B7EA-CD7563DE5770}.Release|Any CPU.ActiveCfg = Release|Any CPU
25+
{AF06AB51-3B39-4905-B7EA-CD7563DE5770}.Release|Any CPU.Build.0 = Release|Any CPU
26+
{ADB00BD6-8FEE-4176-BE15-4F530F5C8F29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{ADB00BD6-8FEE-4176-BE15-4F530F5C8F29}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{ADB00BD6-8FEE-4176-BE15-4F530F5C8F29}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{ADB00BD6-8FEE-4176-BE15-4F530F5C8F29}.Release|Any CPU.Build.0 = Release|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
36+
EndGlobalSection
37+
EndGlobal
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Release History
2+
3+
## 1.0.0-beta.1 (2021-04-23)
4+
- Initial beta release.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<!--
3+
Add any shared properties you want for the projects under this package directory that need to be set before the auto imported Directory.Build.props
4+
-->
5+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory).., Directory.Build.props))\Directory.Build.props" />
6+
</Project>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Azure Web PubSub service client library for .NET
2+
3+
[Azure Web PubSub Service](https://aka.ms/awps/doc) is a service that enables you to build real-time messaging web applications using WebSockets and the publish-subscribe pattern. Any platform supporting WebSocket APIs can connect to the service easily, e.g. web pages, mobile applications, edge devices, etc. The service manages the WebSocket connections for you and allows up to 100K **concurrent** connections. It provides powerful APIs for you to manage these clients and deliver real-time messages.
4+
5+
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.
6+
7+
This library can be used to do the following actions. Details about the terms used here are described in [Key concepts](#key-concepts) section.
8+
9+
- Send messages to hubs and groups.
10+
- Send messages to particular users and connections.
11+
- Organize users and connections into groups.
12+
- Close connections
13+
- Grant, revoke, and check permissions for an existing connection
14+
15+
[Source code](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/webpubsub/Azure.Messaging.WebPubSub/src) |
16+
Package TBD |
17+
[API reference documentation](https://aka.ms/awps/sdk/csharp) |
18+
[Product documentation](https://aka.ms/awps/doc) |
19+
[Samples][samples_ref]
20+
21+
## Getting started
22+
23+
### Install the package
24+
25+
Install the client library from [NuGet](https://www.nuget.org/):
26+
27+
```PowerShell
28+
dotnet add package Azure.Messaging.WebPubSub --prerelease
29+
```
30+
31+
### Prerequisites
32+
33+
- An [Azure subscription][azure_sub].
34+
- An existing Azure Web PubSub service instance.
35+
36+
### Authenticate the client
37+
38+
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.
39+
40+
### Create a `WebPubSubServiceClient`
41+
42+
```csharp
43+
var serviceClient = new WebPubSubServiceClient(new Uri("<endpoint>"), "<hub>", new AzureKeyCredential("<access-key>"));
44+
```
45+
46+
## Key concepts
47+
48+
### Connection
49+
50+
Connections, represented by a connection id, represent an individual websocket connection to the Web PubSub service. Connection id is always unique.
51+
52+
### Hub
53+
54+
Hub is a logical concept for a set of connections. Connections are always connected to a specific hub. Messages that are broadcast to the hub are dispatched to all connections to that hub. Hub can be used for different applications, different applications can share one Azure Web PubSub service by using different hub names.
55+
56+
### Group
57+
58+
Group allow broadcast messages to a subset of connections to the hub. You can add and remove users and connections as needed. A client can join multiple groups, and a group can contain multiple clients.
59+
60+
### User
61+
62+
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.
63+
64+
### Message
65+
66+
Using this library, you can send messages to the client connections. A message can either be string text, JSON or binary payload.
67+
68+
## Examples
69+
70+
### Broadcast a text message to all clients
71+
72+
```csharp
73+
var serviceClient = new WebPubSubServiceClient(new Uri("<endpoint>"), "<hub>", new AzureKeyCredential("<access-key>"));
74+
await serviceClient.SendToAll("Hello world!");
75+
```
76+
77+
### Broadcast a JSON message to all clients
78+
79+
```csharp
80+
var serviceClient = new WebPubSubServiceClient(new Uri("<endpoint>"), "<hub>", new AzureKeyCredential("<access-key>"));
81+
await serviceClient.SendToAll(
82+
RequestContent.Create(
83+
new {
84+
Foo = "Hello World!",
85+
Bar = 42
86+
}));
87+
```
88+
89+
### Broadcast a binary message to all clients
90+
91+
```csharp
92+
var serviceClient = new WebPubSubServiceClient(new Uri("<endpoint>"), "<hub>", new AzureKeyCredential("<access-key>"));
93+
94+
client.SendToAll(
95+
RequestContent.Create(new byte[] {0x1, 0x2, 0x3}),
96+
HttpHeader.Common.OctetStreamContentType.Value
97+
);
98+
```
99+
100+
## Troubleshooting
101+
102+
### Setting up console logging
103+
You can also easily [enable console logging](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md#logging) if you want to dig deeper into the requests you're making against the service.
104+
105+
## Next steps
106+
107+
Please take a look at the
108+
[samples][samples_ref]
109+
directory for detailed examples on how to use this library.
110+
111+
## Contributing
112+
113+
This project welcomes contributions and suggestions.
114+
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.
115+
For details, visit <https://cla.microsoft.com.>
116+
117+
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).
118+
Simply follow the instructions provided by the bot.
119+
You will only need to do this once across all repos using our CLA.
120+
121+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
122+
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
123+
124+
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-net%2Fsdk%2Ftemplate%2FAzure.Template%2FREADME.png)
125+
126+
[azure_sub]: https://azure.microsoft.com/free/
127+
[samples_ref]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/webpubsub/Azure.Messaging.WebPubSub/tests/Samples/

0 commit comments

Comments
 (0)