請注意,這不是MassTransit 訊息型別不能是系統型別例外的重復問題。
我RabbitMQ
在Asp.NET Core Web API (.Net 6)
. 我可以使用的方法成功發布自定義物件,但是,每當我嘗試發送物件的發布串列時,我都會收到此錯誤:Publish
IPublishEndpoint
System.ArgumentException: Messages types must not be System type
這是完整的示例:
public class WeatherForecastController : ControllerBase
{
private readonly IPublishEndpoint _publishEndpoint;
public WeatherForecastController(IPublishEndpoint publishEndpoint)
{
_publishEndpoint = publishEndpoint;
}
[HttpGet(Name = "GetWeatherForecast")]
public async Task<IEnumerable<WeatherForecast>> Get()
{
var data = Enumerable.Range(1, 3).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
myDictionary = new Dictionary<string, string>
{
{ "key1", "value1" },
{ "key2", "value2" }
}
}).ToList();
//Error!
await _publishEndpoint.Publish<IList<WeatherForecast>>(data);
//Working
//await _publishEndpoint.Publish<WeatherForecast>(data.FirstOrDefault());
return data;
}
}
而在Program.cs
builder.Services.AddMassTransit(options => {
options.UsingRabbitMq((context, cfg) =>
{
cfg.Host(new Uri("rabbitmq://localhost:5672"), h =>
{
h.Username("guest");
h.Password("guest");
});
});
});
為什么我不能使用IList
withPublish
方法?
uj5u.com熱心網友回復:
您不能使用IList<T>
with,Publish
因為它不受支持。有一些PublishBatch
擴展方法可以列舉串列并呼叫Publish
每個元素。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/483201.html
標籤:C# asp.net-core-webapi 轨道交通
上一篇:Unity-虛擬搖桿-相機旋轉