-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sticky to one service connection if not in async scope (#2023)
* Add a byte partitionkey for unscoped message sending
- Loading branch information
Showing
13 changed files
with
443 additions
and
110 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,50 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
|
||
using ChatSample.Net60.Hubs; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace ChatSample.Net60 | ||
{ | ||
public class StreamingService : IHostedService | ||
{ | ||
private readonly IHubContext<ChatHub> _hubContext; | ||
private readonly ILogger<StreamingService> _logger; | ||
|
||
public StreamingService(IHubContext<ChatHub> hubContext, ILogger<StreamingService> logger) { | ||
_hubContext = hubContext; | ||
_logger = logger; | ||
} | ||
public Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.Factory.StartNew(() => StreamingTask(cancellationToken), TaskCreationOptions.LongRunning); | ||
} | ||
|
||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
private async Task StreamingTask(CancellationToken cancellationToken) | ||
{ | ||
long counter = 0; | ||
|
||
_logger.LogInformation("Waiting"); | ||
|
||
await Task.Delay(5000); | ||
|
||
_logger.LogInformation("Spamming"); | ||
|
||
while (!cancellationToken.IsCancellationRequested) | ||
{ | ||
counter++; | ||
|
||
await _hubContext.Clients.All.SendAsync("ReceiveMessage", counter, counter); | ||
|
||
await Task.Delay(1); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.