GithubHelp home page GithubHelp logo

wps-function-poc's Introduction

Azure WebJobs Web PubSub client library for .NET

This extension provides data models using in communication with Web PubSub Service.

Getting started

Install the package

Install the package with NuGet:

dotnet add package Microsoft.Azure.WebPubSub.Common

Prerequisites

You must have an Azure subscription and an Azure resource group with a Web PubSub resource. Follow this step-by-step tutorial to create an Azure Web PubSub instance.

Key concepts

Using Web PubSub input binding

Please follow the input binding tutorial to learn about using this extension for building WebPubSubConnection to create Websockets connection to service with input binding.

Using Web PubSub output binding

Please follow the output binding tutorial to learn about using this extension for publishing Web PubSub messages.

Using Web PubSub trigger

Please follow the trigger binding tutorial to learn about triggering an Azure Function when an event is sent from service upstream.

Examples

Functions that uses Web PubSub input binding

[FunctionName("WebPubSubInputBindingFunction")]
public static WebPubSubConnection Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req,
    [WebPubSubConnection(Hub = "simplechat", UserId = "{query.userid}")] WebPubSubConnection connection)
{
    Console.WriteLine("login");
    return connection;
}

Functions that uses Web PubSub output binding

[FunctionName("WebPubSubOutputBindingFunction")]
public static async Task RunAsync(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req,
    [WebPubSub(Hub = "simplechat")] IAsyncCollector<WebPubSubOperation> operation)
{
    await operation.AddAsync(new SendToAll
    {
        Message = BinaryData.FromString("Hello Web PubSub"),
        DataType = MessageDataType.Text
    });
}

Functions that uses Web PubSub trigger

[FunctionName("WebPubSubTriggerFunction")]
public static async Task<MessageResponse> RunAsync(
    [WebPubSubTrigger("message", WebPubSubEventType.User)] 
    ConnectionContext context,
    string message,
    MessageDataType dataType)
{
    Console.WriteLine($"Request from: {context.userId}");
    Console.WriteLine($"Request message: {message}");
    Console.WriteLine($"Request message DataType: {dataType}");
    return new MessageResponse
    {
        Message = BinaryData.FromString("ack"),
    };
}

Troubleshooting

Please refer to Monitor Azure Functions for troubleshooting guidance.

Next steps

Read the introduction to Azure Function or creating an Azure Function guide.

Contributing

See our CONTRIBUTING.md for details on building, testing, and contributing to this library.

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 cla.microsoft.com.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Impressions

wps-function-poc's People

Contributors

jialinxin avatar

Watchers

 avatar  avatar

wps-function-poc's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.