美好的一天,我正在為 .net6 網路核心應用程式配置 Masstransit 添加了 Masstransit nuget 包:
<PackageReference Include="MassTransit.Extensions.DependencyInjection" Version="7.2.4" />
<PackageReference Include="MassTransit.RabbitMQ" Version="7.2.4" />
我在 Startup 中注冊它,它說沒有像 AddMasstransitHostedService 這樣的方法我試過在沒有它的情況下發布訊息,但沒有創建交換(出于某種原因,除錯還顯示埠 0 的實際地址)
非常感謝您的幫助已在互聯網上搜索了所有相關內容,不幸的是還沒有修復
這是我注冊大眾運輸的方式:
services.AddMassTransit(mt =>
{
mt.UsingRabbitMq((context, cfg) =>
{
cfg.Host(new Uri(RabbitMqOptions.RabbitMqUri), h =>
{
h.Username(RabbitMqOptions.UserName);
h.Password(RabbitMqOptions.Password);
});
cfg.AutoStart = true;
cfg.Publish<IServerNotificationMessage>(e => e.ExchangeType = RabbitMQ.Client.ExchangeType.Direct);
});
});
services.AddMassTransitHostedService();//<-----this one hints: IServiceCollection doesnt contain a definition for AddMassTransitHostedService...
這是我嘗試發布訊息的方式:
public class SomeController : ControllerBase
{
protected readonly IBus _bus;
public SomeController(IBus bus)
{
_bus = bus;
}
[HttpGet("TestPublish")]
public void TestPublish(CancellationToken cancellationToken)
{
_bus.Publish<SomeMessage>(new
{
...
... // fields go here
}, cancellationToken);
uj5u.com熱心網友回復:
您需要添加MassTransit.AspNetCore包參考。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/371006.html
