Skip to content

Feature: Support streaming in serverless. #2132

@vwxyzh

Description

@vwxyzh

Goal

In serverless mode, customer can also use streaming feature in SignalR.

Overview

sequenceDiagram
    participant c as Client
    participant s as Service
    participant u as Upstream
    participant g as Stream Generator

    c->>s: Stream Invocation
    s->>u: Rest API<br>(Stream Invocation)
    u->>+g: Generate
    loop
        g-->>s: Send partial result
        s-->>c: Send partial result
    end
    g-->>-s: Complete stream
    s-->>c: Complete stream
Loading

Programming model

Client

Clients initialize streams by current stream invocation like followings:

function invokeStream() {
    const stream = connection.stream("YourStreamingMethod", arg1, arg2);

    stream.subscribe({
        next: (item) => {
            console.log(item); // Handle each item received from the stream
        },
        error: (err) => {
            console.error(err); // Handle any errors
        },
        complete: () => {
            console.log("Stream completed"); // Handle stream completion
        }
    });
}

Function

Function binding will handle REST API requests to a method invocation.
In the method invocation, it will start a generator with connection id, stream id and arguments in long run. And the method should return void.

Generator

Generator uses our Data Plane API to send stream item back to client.

Data Plane API

  • c#: Microsoft.Azure.SignalR.Management

    IServiceHubContext context = ...
    IAsyncEnumerable<string> stream = ...
    await context.Streams.SendStreamAsync(connectionId, streamId, stream, cancellationToken);
  • Rest API: swagger coming soon.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions