Created
September 5, 2019 08:15
-
-
Save tocalai/e63b99591d62035a5f9e9933fea620fa to your computer and use it in GitHub Desktop.
Demonstrate sending message to specific client(s) according group.
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
using Microsoft.AspNetCore.SignalR; | |
using Newtonsoft.Json; | |
using SignalR.Lab.Web.Hubs; | |
using SignalR.Lab.Web.Models; | |
using System; | |
using System.Timers; | |
namespace SignalR.Lab.Web.Services | |
{ | |
public class EventReceiverService | |
{ | |
// ..... | |
private void MockEventGenTimer_Elapsed(object sender, ElapsedEventArgs e) | |
{ | |
_mockEventGenTimer.Enabled = false; | |
var mockEvent = new EventModel() | |
{ | |
Content = $"{new Random().Next()}" | |
}; | |
// target to line1 or line2 or line3 | |
var target = new Random().Next(1, 4); | |
// implement and invoke send message to group | |
_eventHub.Clients.Group($"Line{target}").SendAsync(nameof(IEventHub.SendMessageToGroup), | |
$"Line{target}", JsonConvert.SerializeObject(mockEvent)).GetAwaiter().GetResult(); | |
_mockEventGenTimer.Enabled = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment