1

I am having Asp.Net Core 2.1 with SignalR Core 1.0.1.

I have created chat application that is described here: https://learn.microsoft.com/en-us/aspnet/core/tutorials/signalr?view=aspnetcore-2.1&tabs=visual-studio

Also have configured SignalR to use Redis using

services.AddSignalR().AddRedis(Configuration["ConnectionStrings:Redis"]);

Having running Redis server up with redis-cli monitor I can see the following commands coming:

1530086417.413730 [0 127.0.0.1:57436] "SUBSCRIBE" "SignalRCore.Hubs.ChatHub:connection:VAIbFqtNyPVaod18jmm_Aw"

1530086428.181854 [0 127.0.0.1:57435] "PUBLISH" "SignalRCore.Hubs.ChatHub:all" "\x92\x90\x81\xa4json\xc4W{\"type\":1,\"target\":\"ReceiveMessage\",\"arguments\":[{\"user\":\"user\",\"message\":\"message\"}]}\x1e"

Everything works fine till the time when I would like to push some message from another console application. In that application I am using ServiceStack.Redis and the code is the following:

var redisManager = new RedisManagerPool(configuration["ConnectionStrings:Redis"]);
using (var client = redisManager.GetClient())
{
    client.PublishMessage("SignalRCore.Hubs.ChatHub:all", "{\"type\":1,\"target\":\"ReceiveMessage\",\"arguments\":[{\"user\":\"FromConsole\",\"message\":\"Message\"}]");
}

The messages are not handled by browser. I assume the case is in this additional information that is used for SignalR:

"\x92\x90\x81\xa4json\xc4W{...}\x1e"

Related monitor record:

1530087843.512083 [0 127.0.0.1:49480] "PUBLISH" "SignalRCore.Hubs.ChatHub:all" "{\"type\":1,\"target\":\"ReceiveMessage\",\"arguments\":[{\"user\":\"FromConsole\",\"message\":\"Message\"}]"

Any ideas how can I specify this additional data for publish? Probably I should use something more suitable for my case instead of ServiceStack.Redis

Volodymyr Ivanov
  • 159
  • 2
  • 12

1 Answers1

2
using Microsoft.AspNetCore.SignalR.Protocol;

using Microsoft.AspNetCore.SignalR.Redis.Internal;

using StackExchange.Redis;

using System.Collections.Generic;

    static void Main(string[] args)
    {
        using (var redis = ConnectionMultiplexer.Connect("127.0.0.1:6379"))
        {
            var sub = redis.GetSubscriber();

            var protocol = new JsonHubProtocol();
            var redisProtocol = new RedisProtocol(new List<JsonHubProtocol>() { protocol});
            var bytes = redisProtocol.WriteInvocation("ReceiveMessage", new[] { "60344", "60344" });

            sub.Publish("SignalRChat.Hubs.ChatHub:all", bytes);
        }
    }

How to find it?

  1. In ASP.NET's source code search .Publish, you can find the https://github.com/dotnet/aspnetcore/blob/main/src/SignalR/server/StackExchangeRedis/src/RedisHubLifetimeManager.cs

  2. It uses the RedisProtocol and messagepack to .WriteBytes header footer name count...

double-beep
  • 5,031
  • 17
  • 33
  • 41