AzureSignalRExtensions.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using System.Linq;
  8. using StackExchange.Redis;
  9. using System.Collections.Concurrent;
  10. using Microsoft.Azure.SignalR.Management;
  11. namespace TEAMModelOS.SDK.DI
  12. {
  13. public static class AzureSignalRExtensions
  14. {
  15. private static ConcurrentDictionary<string, ServiceHubContext> ServiceHubContexts { get; } = new();
  16. /// <summary>
  17. /// µo°e«H®§¦Ü¹ï¦C©Î¥DÃD
  18. /// </summary>
  19. /// <param name="name">QueueName or TopicName</param>
  20. /// <param name="message">°T®§</param>
  21. /// <returns></returns>
  22. public static ServiceHubContext GetHubContext(this ServiceManager sm, string name)
  23. {
  24. try
  25. {
  26. ServiceHubContext hub = ServiceHubContexts.GetOrAdd(name, (x) =>
  27. sm.CreateHubContextAsync(name, CancellationToken.None).ConfigureAwait(false).GetAwaiter().GetResult());
  28. return hub;
  29. }
  30. catch
  31. {
  32. throw;
  33. }
  34. }
  35. }
  36. }