dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.58k stars 25.3k forks source link

Bidirectional communication #16966

Open cowwoc opened 4 years ago

cowwoc commented 4 years ago

Please provide an example showing bidirectional communication where the server sends information to the client, and the client acknowledges receipt based on a message id.

Justification: SignalR does not guarantee message delivery. This design pattern can be used to detect dropped messages.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

bradygaster commented 4 years ago

I fully support a doc of this nature, provided we could author it as a demonstrative topic and not as a guidance topic. I'd prefer avoid "guidance" as there are so many scenarios and ways to solve this problem. If @davidfowl and @anurse concur, I'd like to have this be one of our priority documentation items for the next wave.

stephenwelsh commented 4 years ago

I've been unable to get bidirectional streams to work, as soon as one stream completes so does the other. I assume there is a single TaskCompletion per connection that causes this behaviour. I initial used the following to setup bi-directional channels in one request, if I use/complete only one channel (i.e. readChannel) it works fine, but if I try to use the second (i.e. writeChannel) I can't as it's flagged as completed.

var writeChannel = Channel.CreateUnbounded<Byte[]>();
var readChannel = await _connection.StreamAsChannelAsync<Byte[]>("GetChannel", Id, writeChannel.Reader);

If this does/can work, awesome and a documented example would be perfect. If confirmed as an issue/restriction it should be documented accordingly. In my case I simply setup and complete one channel/direction at a time, but more complex requirements may not work

bradygaster commented 4 years ago

This is an area in which we wanted to invest in .NET 5. Currently this may be a bit further out, but I think it'd be good in the meantime if we could provide some guidance on how to do this. @BrennanConroy wrote up the fantastic example StreamR to demonstrate client and server streaming. In this example he implemented a custom class - the StreamManager that does some of this management for the Hub. Whilst I want to preclude this guidance by saying this is a sample and isn't quite what we'd recommend you'd do in production (as you'd need to be a bit more cognizant of the potential of how the streams could allocate resources in your app than we are in this example), it should provide an illustration of how to juggle multiple clients with streams.

@BrennanConroy - what say you we collaborate on an update to the docs on this? I have some use cases in mind (don't I always?) for the multiple-client streaming scenarios.

BrennanConroy commented 4 years ago

Improving the docs is always nice :)

I'd love to collab.