-
Notifications
You must be signed in to change notification settings - Fork 912
Go SDK for Azure Web PubSub Data plane #21929
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
578b617
generated codespec for web pubsub
MBSolomon d739152
Updating readme and autorest
vicancy a0f1510
Adding custom client and test code
vicancy f97c894
Add GenerateClientAccessUrl
vicancy fa26292
Resolve comments
vicancy 2d85a69
resolve comments
vicancy 9dc1a06
Update readme
vicancy ea0ea0b
fix some comments, remove hub parameter when constructing the client,…
vicancy 9cd024c
Fix go vet error
vicancy abb89b6
Fix test failure
vicancy 0af1a21
Fix comments
vicancy be5c100
Adding recording
vicancy 9abb7da
Use asset repo
vicancy ee72d15
Remove skip
vicancy 273311a
Fix comment
vicancy 7aa5b0e
adding main test logic to start the test-proxy
vicancy 89a5993
update CI settings
vicancy 7ddb1a2
Fix test failure
vicancy 9374f1c
Update link to temp URL to pass CI
vicancy e3f8642
Fix doc comment
vicancy 92a2196
Update CHANGELOG.md
vicancy fe3a152
resolve comments
vicancy 6f47a7b
Update sdk/messaging/azwebpubsub/ci.yml
vicancy eb2a69d
Update sdk/messaging/azwebpubsub/sample.env
vicancy e15adaf
Resolving comments
vicancy 00af501
resolve comments
vicancy e8fb8cc
remove healthclient
vicancy a029bdc
Resolve comments
vicancy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Release History | ||
|
||
## 0.1.0 (Unreleased) | ||
|
||
* Initial version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Microsoft Corporation. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
azwebpubsub | ||
|
||
NOTICES AND INFORMATION | ||
Do Not Translate or Localize | ||
|
||
This software incorporates material from third parties. Microsoft makes certain | ||
open source code available at https://3rdpartysource.microsoft.com, or you may | ||
send a check or money order for US $5.00, including the product name, the open | ||
source component name, and version number, to: | ||
|
||
Source Code Compliance Team | ||
Microsoft Corporation | ||
One Microsoft Way | ||
Redmond, WA 98052 | ||
USA | ||
|
||
Notwithstanding any other terms, you may reverse engineer this software to the | ||
extent required to debug changes to any libraries licensed under the GNU Lesser | ||
General Public License. | ||
|
||
------------------------------------------------------------------------------ | ||
|
||
Azure SDK for Go uses third-party libraries or other resources that may be | ||
distributed under licenses different than the Azure SDK for Go software. | ||
|
||
In the event that we accidentally failed to list a required notice, please | ||
bring it to our attention. Post an issue or email us: | ||
|
||
@microsoft.com | ||
|
||
The attached notices are provided for information only. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
# Azure Web PubSub service client library for Go | ||
|
||
[Azure Web PubSub service](https://aka.ms/awps/doc) 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: | ||
|
||
. | ||
|
||
- 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](#key-concepts) section. | ||
|
||
Key links: | ||
- [Source code][source] | ||
- [API Reference Documentation][godoc] | ||
- [Product documentation][product] | ||
- [Samples][godoc_examples] | ||
|
||
## Getting started | ||
|
||
### Install the package | ||
|
||
Install the Azure Web PubSub service client module for Go with `go get`: | ||
|
||
```bash | ||
go get github.com/Azure/azure-sdk-for-go/sdk/messaging/azwebpubsub | ||
``` | ||
|
||
### Prerequisites | ||
|
||
- Go, version 1.18 or higher | ||
- An [Azure subscription](https://azure.microsoft.com/free/) | ||
- An existing Azure Web PubSub service instance. | ||
|
||
|
||
### Authenticate the client | ||
|
||
Web PubSub service clients are created using a TokenCredential from the [Azure Identity package][azure_identity_pkg], like [DefaultAzureCredential][default_azure_credential]. | ||
You can also create a client using a connection string. | ||
|
||
#### Using a service principal | ||
|
||
Constructing the client requires your Web PubSub's endpoint URL, which you can get from the Azure Portal (`Host name` value on overview page with `https` scheme). | ||
|
||
```go | ||
import ( | ||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity" | ||
"github.com/Azure/azure-sdk-for-go/sdk/messaging/azwebpubsub" | ||
"log" | ||
) | ||
|
||
func main() { | ||
cred, err := azidentity.NewDefaultAzureCredential(nil) | ||
if err != nil { | ||
log.Fatalf("failed to obtain a credential: %v", err) | ||
} | ||
|
||
client, err := azwebpubsub.NewClient("<your Web PubSub's endpoint URL>", "<your hub name>", cred, nil) | ||
if err != nil { | ||
log.Fatalf("failed to create client: %v", err) | ||
} | ||
} | ||
``` | ||
|
||
#### Using a connection string | ||
|
||
ConnectionString can be found in the **Keys** tab from your Web PubSub resource portal. | ||
|
||
```go | ||
import ( | ||
"github.com/Azure/azure-sdk-for-go/sdk/azidentity" | ||
"github.com/Azure/azure-sdk-for-go/sdk/messaging/azwebpubsub" | ||
"log" | ||
) | ||
|
||
func main() { | ||
client, err := azwebpubsub.NewClientFromConnectionString("<your Web PubSub's connection string>", "<your hub name>", nil) | ||
if err != nil { | ||
log.Fatalf("failed to create client: %v", err) | ||
} | ||
} | ||
``` | ||
|
||
# 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 the client is connected, it can send messages to the upstream application, or receive messages from the upstream application, through the WebSocket connection. | ||
|
||
# Examples | ||
|
||
Examples for various scenarios can be found on [pkg.go.dev](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/messaging/azwebpubsub#pkg-examples) or in the example*_test.go files in our GitHub repo for [azwebpubsub](https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/messaging/azwebpubsub). | ||
|
||
# Troubleshooting | ||
|
||
### Live Trace | ||
|
||
Use **Live Trace** from the Web PubSub service portal to view the live traffic. | ||
|
||
### Logging | ||
|
||
This module uses the classification-based logging implementation in `azcore`. To enable console logging for all SDK modules, set the environment variable `AZURE_SDK_GO_LOGGING` to `all`. | ||
|
||
Use the `azcore/log` package to control log event output or to enable logs for `azwebpubsub` only. For example: | ||
|
||
```go | ||
import ( | ||
"fmt" | ||
azlog "github.com/Azure/azure-sdk-for-go/sdk/azcore/log" | ||
) | ||
|
||
// print log output to stdout | ||
azlog.SetListener(func(event azlog.Event, s string) { | ||
fmt.Printf("[%s] %s\n", event, s) | ||
}) | ||
|
||
// pick the set of events to log | ||
azlog.SetEvents( | ||
azwebpubsub | ||
) | ||
``` | ||
|
||
## Contributing | ||
For details on contributing to this repository, see the [contributing guide][azure_sdk_for_go_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](https://opensource.microsoft.com/codeofconduct/). | ||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or | ||
contact [[email protected]](mailto:[email protected]) with any additional questions or comments. | ||
|
||
### Additional Helpful Links for Contributors | ||
Many people all over the world have helped make this project better. You'll want to check out: | ||
|
||
* [What are some good first issues for new contributors to the repo?](https://github.com/azure/azure-sdk-for-go/issues?q=is%3Aopen+is%3Aissue+label%3A%22up+for+grabs%22) | ||
* [How to build and test your change][azure_sdk_for_go_contributing_developer_guide] | ||
* [How you can make a change happen!][azure_sdk_for_go_contributing_pull_requests] | ||
* Frequently Asked Questions (FAQ) and Conceptual Topics in the detailed [Azure SDK for Go wiki](https://github.com/azure/azure-sdk-for-go/wiki). | ||
|
||
<!-- ### Community--> | ||
### Reporting security issues and security bugs | ||
|
||
Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) <[email protected]>. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the [Security TechCenter](https://www.microsoft.com/msrc/faqs-report-an-issue). | ||
|
||
### License | ||
|
||
Azure SDK for Go is licensed under the [MIT](https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/template/aztemplate/LICENSE.txt) license. | ||
|
||
<!-- LINKS --> | ||
[azure_sdk_for_go_contributing]: https://github.com/Azure/azure-sdk-for-go/blob/main/CONTRIBUTING.md | ||
[azure_sdk_for_go_contributing_developer_guide]: https://github.com/Azure/azure-sdk-for-go/blob/main/CONTRIBUTING.md#developer-guide | ||
[azure_sdk_for_go_contributing_pull_requests]: https://github.com/Azure/azure-sdk-for-go/blob/main/CONTRIBUTING.md#pull-requests | ||
[azure_cli]: https://docs.microsoft.com/cli/azure | ||
[azure_pattern_circuit_breaker]: https://docs.microsoft.com/azure/architecture/patterns/circuit-breaker | ||
[azure_pattern_retry]: https://docs.microsoft.com/azure/architecture/patterns/retry | ||
[azure_portal]: https://portal.azure.com | ||
[azure_sub]: https://azure.microsoft.com/free/ | ||
[cloud_shell]: https://docs.microsoft.com/azure/cloud-shell/overview | ||
[cloud_shell_bash]: https://shell.azure.com/bash | ||
|
||
[azure_identity_pkg]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity | ||
[default_azure_credential]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity#NewDefaultAzureCredential | ||
[source]: https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/messaging/azwebpubsub | ||
[godoc]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/messaging/azwebpubsub | ||
[godoc_examples]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/messaging/azwebpubsub#pkg-examples | ||
[product]: https://aka.ms/awps/doc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## Go | ||
|
||
```yaml | ||
title: WebPubSub | ||
description: Azure Web PubSub client | ||
clear-output-folder: false | ||
export-clients: true | ||
vicancy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
go: true | ||
input-file: https://github.com/Azure/azure-rest-api-specs/blob/052a4b8d50bfd5595a8b5b506015d18f2b65998d/specification/webpubsub/data-plane/WebPubSub/stable/2023-07-01/webpubsub.json | ||
license-header: MICROSOFT_MIT_NO_VERSION | ||
module: github.com/Azure/azure-sdk-for-go/sdk/messaging/azwebpubsub | ||
openapi-type: "data-plane" | ||
output-folder: ../azwebpubsub | ||
use: "@autorest/[email protected]" | ||
vicancy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
directive: | ||
# Make GenerateClientToken internal. | ||
- from: client.go | ||
where: $ | ||
transform: return $.replace(/\bGenerateClientToken\b/g, "generateClientToken"); | ||
# Make *Exists internal until SDK supports it. | ||
- from: client.go | ||
where: $ | ||
transform: return $.replace(/\b(Group|Connection|User)Exists\b/g, function(match, group) { return group.toLowerCase() + "Exists";}); | ||
# Add more properties to lient | ||
- from: client.go | ||
where: $ | ||
transform: >- | ||
return $.replace( | ||
/(type Client struct[^}]+})/s, | ||
"type Client struct {\n internal *azcore.Client\n endpoint string\n hub string\n key *string\n}") | ||
|
||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
//go:generate autorest ./autorest.md | ||
//go:generate goimports -w . | ||
vicancy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
package azwebpubsub |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. | ||
trigger: | ||
branches: | ||
include: | ||
- main | ||
- feature/* | ||
- hotfix/* | ||
- release/* | ||
paths: | ||
include: | ||
- sdk/messaging/azwebpubsub/ | ||
- eng/ | ||
vicancy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
pr: | ||
branches: | ||
include: | ||
- main | ||
- feature/* | ||
- hotfix/* | ||
- release/* | ||
paths: | ||
include: | ||
- sdk/messaging/azwebpubsub/ | ||
- eng/ | ||
|
||
|
||
stages: | ||
- template: /eng/pipelines/templates/jobs/archetype-sdk-client.yml | ||
parameters: | ||
ServiceDirectory: 'messaging/azwebpubsub/' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.