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?
--
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.
Здравствуйте!Я новичок в МассТранзит и Сигнал
У меня была проблема с отправкой сообщений клиентам через 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.
Что я делаю неправильно?