.net core MassTransit信号绑定
我在设置MassTransit信号解决方案时遇到一些问题。我之前发布了一个关于绑定的问题,Chris回答并帮助我解决了这个问题,但是在更新包之后(我仍然使用6.x.x,它还有其他问题,比如重新启动RabbitMQ服务会在发送消息时出错),我的绑定似乎不再正常工作 这是我问的第一个问题: 现在我已经更新到了7.1.7,还更新了不推荐使用的方法。这就是我的创业公司的样子:.net core MassTransit信号绑定,.net-core,rabbitmq,signalr,masstransit,.net Core,Rabbitmq,Signalr,Masstransit,我在设置MassTransit信号解决方案时遇到一些问题。我之前发布了一个关于绑定的问题,Chris回答并帮助我解决了这个问题,但是在更新包之后(我仍然使用6.x.x,它还有其他问题,比如重新启动RabbitMQ服务会在发送消息时出错),我的绑定似乎不再正常工作 这是我问的第一个问题: 现在我已经更新到了7.1.7,还更新了不推荐使用的方法。这就是我的创业公司的样子: public void ConfigureServices(IServiceCollection services) {
public void ConfigureServices(IServiceCollection services)
{
Utilities utilities = new Utilities(Configuration);
RabbitMQIdentity rabbitMQIdentity = utilities.GetRabbitMQIdentity();
var username = rabbitMQIdentity.UserName;
var password = rabbitMQIdentity.Password;
var hostName = rabbitMQIdentity.HostName;
var portNumber = rabbitMQIdentity.Port;
services.AddHttpClient();
services.AddControllers();
services.AddSignalR(e => {
e.EnableDetailedErrors = true;
e.MaximumReceiveMessageSize = 102400000;
});
services.AddMassTransit(x =>
{
x.AddSignalRHub<NotificationHub>();
x.UsingRabbitMq((context, cfg) =>
{
cfg.Host($"amqp://{username}:{password}@{hostName}:{portNumber}");
cfg.AutoDelete = true;
cfg.Durable = false;
cfg.QueueExpiration = TimeSpan.FromMinutes(10);
cfg.ConfigureEndpoints(context);
});
});
services.AddMassTransitHostedService();
services.AddSingleton<IHostEnvironment>(hostEnvironment);
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<LogConfigurationUtility, WebLogConfigurationUtility>();
services.AddCors(options =>
{
options.AddDefaultPolicy(builder =>
{
builder.SetIsOriginAllowed((x) => Configuration["CorsWhiteList"].Split(';').Any(x.Contains))
.WithMethods("GET", "POST")
.AllowAnyHeader()
.AllowCredentials();
});
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseCors();
app.UseMiddleware<RequestMiddleware>();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<NotificationHub>("/notificationhub");
});
}
现在,在RabbitMQ管理工具中,我可以看到正在创建exchange,但它没有绑定,也没有队列。克里斯,同样的问题还存在吗?还是我做错了什么
谢谢你的帮助 正如所述,是一个需要检查的工作基线。我找到了绑定不工作的原因。正如我所说的,我使用较低的MT版本(6..)执行了rabbitMQ重启,然后发现有一个关于重启的问题已经解决,因为终结点不是由MT创建的。所以我更新了包和DI代码,但它仍然不起作用。我必须重新安装rabbitMQ才能让masstransit再次创建我的端点,似乎更新包和重新尝试beggining的流程是不够的,这导致了我的问题。感谢Chris的帮助和你花在帮助我上的时间,我建议您添加更多关于信号机背板如何与masstransit和集线器工作/通信的信息。这方面的实现并不多,更详细地了解后台发生的事情可以避免一些基本错误。抱歉,重复评论,字符太多
logger.LogInformation($"MassTransit publishing group message. GroupName:{paymentCallback.OrderId} ; Message:{paymentCallback.Event}");
IReadOnlyList <IHubProtocol> protocols = new IHubProtocol[] { new JsonHubProtocol() };
publishEndpoint.Publish<Group<NotificationHub>>(
new GroupHub<NotificationHub>()
{
GroupName = paymentCallback.OrderId,
Messages = protocols.ToProtocolDictionary("Notify", new object[] { paymentCallback.Event })
},
context => context.TimeToLive = TimeSpan.FromMinutes(10)
);
useEffect(() => {
$(function() {
const connection = new HubConnectionBuilder()
.withUrl(hubUrl)
.configureLogging(LogLevel.Trace)
.build();
// Create a function that the hub can call to broadcast messages.
connection.on("Notify", (status) => {
console.log("entrouuuuuu");
setNotification(status);
});
// Start the connection.
async function start() {
try {
await connection.start();
connection.invoke("InitializeClient", orderId);
console.log("SignalR Connected.");
} catch (err) {
setTimeout(start, 5000);
}
}
start();
});