我正在netcore控制台应用程序上使用MassTransit和Rabbit MQ v5.1.4。
假设我有以下内容:
string item = TXTSearchItem.Text;
string foods = sr.ReadToEnd(); // Maybe you already have ReadLines method here
var lines = foods.Split(new []{ Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
var expectedLine = lines.FirstOrDefault($"{item}-"); // assume that you have fixed format here
if (expectedLine != null)
{
var splittedLine = expectedLine.Split('-');
var foodName = splittedLine.First();
var foodCount = splittedLine.Last();
MessageBox.Show($"Item {foodName} is worth {footCount} SmartPoints.", "Item search", MessageBoxButtons.OK, info);
}
else
{
MessageBox.Show("Item was not found.", "Item search", MessageBoxButtons.OK, warning);
}
当我调用有权访问public MassTransitConfigurator()
{
bus = Bus.Factory.CreateUsingRabbitMq(sbc =>
{
var host = sbc.Host(Settings.Rabbit.Uri, h =>
{
h.Username(Settings.Rabbit.User);
h.Password(Settings.Rabbit.Pass);
});
sbc.ReceiveEndpoint(host, Settings.Rabbit.Queue, e =>
{
e.Consumer<FooConsumer>();
e.Consumer<BarConsumer>();
});
sbc.ReceiveEndpoint(host, Settings.Rabbit.FaultQueue, e =>
{
e.Consumer<FooFaultConsumer>();
e.Consumer<BarFaultConsumer>();
});
});
}
实例的方法时,我想记录以下内容:
bus
但是从public void StartListening()
{
bus.Start();
// What to do here so that we get something like:
Console.WriteLine($"Listening on: {Settings.Rabbit.Uri}");
Console.WriteLine($" Queues: ");
Console.WriteLine($" - {Settings.Rabbit.Queue}");
Console.WriteLine($" - {Settings.Rabbit.FaultQueue}");
Console.WriteLine($" Event Types: ");
Console.WriteLine($" - {Foo}");
Console.WriteLine($" - {Bar}");
}
获取数据,而不是手动将其填充到日志中。
我看过官方的documentation,但看不到这样的东西。
注释:
bus
将是记录器类。Console.WriteLine
类是从配置读取的值。答案 0 :(得分:1)
您可以将总线配置输出为对象图,可以使用JSON.NET将其转换为JSON:
http://masstransit-project.com/MassTransit/troubleshooting/show-config.html