我在网络核心中有一个实现signalR的应用程序,此应用程序已连接到实现Masstrasit Rabbit MQ的消息传递总线,该应用程序收集到达已连接总线队列的消息,但这些消息是必要的显示在javascript客户端中。
当消息到达队列的订户时,我调用显示消息的hub方法, 但是这个对象(集线器)被放置了,这意味着连接到集中器(signalR)的所有客户端的信息都会丢失,并且没有客户端可以显示消息。
集线器SignalR
public class ChatHub : Hub
{
public override async Task OnConnectedAsync(){
String user = Context.GetHttpContext().Request.QueryString.Value.Split("=")[1].Split("&")[0];
string appBus = Context.GetHttpContext().Request.QueryString.Value.Split("=")[2].Split("&")[0];
await Groups.AddToGroupAsync(user, "SignalR Users");
await base.OnConnectedAsync();
ClientesModel client = new ClientModel() {
Username = user,
ID = Context.ConnectionId
};
MessageBusConfig.Configure(appBus, this);
}
public void SendAsync(string user, string message) {
Task.Run(async () =>{
await Clients.All.SendAsync("enviamensaje", user, message);
});
}
}
Class Config总线
public class MessageBusConfig
{
public static IBusControl BusControl { get; set; }
public static void Configure(String nameQueue, ChatHub hub)
{
BusControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.AutoDelete = true;
var host = cfg.Host(new Uri("rabbitmq://localhost/"), h =>
{
h.Username("guest");
h.Password("guest");
});
cfg.ReceiveEndpoint(host, nameQueue, e => {
e.Consumer(() => new CheckinCommandProviders(hub));
//e.AutoDelete = true;
});
});
BusControl.Start();
}
}
具有Masstrasit的一流消费者消息总线RabbitMQ
public class CheckinCommandProviders: IConsumer<ContractSuscriber>{
private ChatHub _hub;
public CheckinCommandProveedores(ChatHub hub){
_hub = hub;
}
public Task Consume(ConsumeContext<ContratoSuscriptor> context){
_hub.SenndAsync(context.Message.Usuario, context.Message.Mensaje);
return Task.FromResult<int>(0);
}
}
供应商与订户的接口合同
消费者通过此界面与消息队列进行通信
public interface ContratoSuscriptor
{
string Mensaje { get; set; }
string Usuario { get; set; }
bool IsOk { get; set; }
string filtro { get; set; }
}
主要是到达对象集线器的Menesjae已经放置并且无法显示消息