SignalR client does not receive message through Masstransit

231 views
Skip to first unread message

Alexander Rezvanov

unread,
Apr 29, 2020, 12:39:55 AM4/29/20
to masstransit-discuss


Hello!

I'm new to MassTransit and Signal

I had a problem sending messages to clients via MassTransit and SignalR


Startup:

 //SignalR
        services.AddSignalR().AddMassTransitBackplane();     
        #region MassTransit RabbitMq

        services.AddScoped<SendCosistListToScaleConsumer>();
        services.AddScoped<CreateConsistListConsumer>();

        services.AddMassTransit(x => 
        {
            x.AddSignalRHubConsumers<NotifyHub>();

            x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(conf =>
            {
                conf.Host(Configuration["Rabbit:Host"], host => {
                    host.Username(Configuration["Rabbit:Username"]);
                    host.Password(Configuration["Rabbit:Password"]);
                });                   

               conf.ReceiveEndpoint(Configuration["Rabbit:ReceiveEndpoint"], e => {
                    e.PrefetchCount = 16;
                    e.UseMessageRetry(n => n.Interval(3, 100));

                    #region Consumers
                    e.Consumer<SendCosistListToScaleConsumer>();
                    e.Consumer<CreateConsistListConsumer>();
                   #endregion
               });
                conf.AddSignalRHubEndpoints<NotifyHub>(provider);
            }));
        });
        services.AddMassTransitHostedService();
        #endregion

....

app.UseSignalR(endpoints =>
{
    endpoints.MapHub<NotifyHub>("/notify");
});


Consumer:

public class CreateConsistListConsumer : IConsumer<ICreateConsistList>
    {
        IReadOnlyList<IHubProtocol> protocols = new IHubProtocol[] { new JsonHubProtocol() };
        public Task Consume(ConsumeContext<ICreateConsistList> context)
        {
            context.Publish<All<NotifyHub>>(
               new
               {
                   Message = protocols.ToProtocolDictionary("SendMessageToAllUsers", new object[] { "CompanyId", context.Message.CompanyId })
               });
            return Task.CompletedTask;
        }
    }


Console App (SignalR Client):

 hubConnection.On<Object>("SendMessageToAllUsers", param => {
        Console.WriteLine(param);
     });


If I understand correctly how MassTransii and SignalR work, then this code is enough to send messages to clients. With the help of debugging, I looked that CreateConsistListConsumer is working, but clients do not receive reporting.   At the same time, the client connects to the hub and correctly receives messages from other sources, but not from MassTransit.

What am I doing wrong?


Chris Patterson

unread,
Apr 29, 2020, 8:56:06 AM4/29/20
to masstrans...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/09ee9934-4bd7-4b8d-aa8f-c83356c18f62%40googlegroups.com.

Alexander Rezvanov

unread,
May 7, 2020, 4:10:33 AM5/7/20
to masstransit-discuss
I still have a problem with this question.
I made an example project. Everything is done according to docummation. But SignalR clients still do not receive messages.
So much time has passed, and I still stand still.



среда, 29 апреля 2020 г., 11:39:55 UTC+7 пользователь Alexander Rezvanov написал:


Здравствуйте!

Я новичок в МассТранзит и Сигнал

У меня была проблема с отправкой сообщений клиентам через MassTransit и SignalR


Запускать:

Потребитель:

public class CreateConsistListConsumer : IConsumer<ICreateConsistList>
    {
        IReadOnlyList<IHubProtocol> protocols = new IHubProtocol[] { new JsonHubProtocol() };
        public Task Consume(ConsumeContext<ICreateConsistList> context)
        {
            context.Publish<All<NotifyHub>>(
               new
               {
                   Message = protocols.ToProtocolDictionary("SendMessageToAllUsers", new object[] { "CompanyId", context.Message.CompanyId })
               });
            return Task.CompletedTask;
        }
    }


Консольное приложение (клиент SignalR):

 hubConnection.On<Object>("SendMessageToAllUsers", param => {
        Console.WriteLine(param);
     });


Если я правильно понимаю, как работают MassTransii и SignalR, то этого кода достаточно для отправки сообщений клиентам. С помощью отладки я посмотрел, что CreateConsistListConsumer работает, но клиенты не получают отчеты. В то же время клиент подключается к концентратору и правильно получает сообщения из других источников, но не из MassTransit.

Что я делаю неправильно?


Reply all
Reply to author
Forward
0 new messages