Skip to content
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

Feature: Support streaming in serverless. #2132

Open
vwxyzh opened this issue Jan 21, 2025 · 0 comments · May be fixed by #2129
Open

Feature: Support streaming in serverless. #2132

vwxyzh opened this issue Jan 21, 2025 · 0 comments · May be fixed by #2129
Assignees
Labels
enhancement New feature or request

Comments

@vwxyzh
Copy link
Contributor

vwxyzh commented Jan 21, 2025

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.

@vwxyzh vwxyzh linked a pull request Jan 21, 2025 that will close this issue
@vwxyzh vwxyzh self-assigned this Jan 22, 2025
@vwxyzh vwxyzh added the enhancement New feature or request label Jan 22, 2025
@vwxyzh vwxyzh changed the title Streaming supports in serverless. Feature: Streaming supports in serverless. Jan 22, 2025
@vwxyzh vwxyzh linked a pull request Jan 22, 2025 that will close this issue
@vwxyzh vwxyzh changed the title Feature: Streaming supports in serverless. Feature: Support streaming in serverless. Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant