How to get size (number of messages) of a MassTransit IBus?

做~自己de王妃 提交于 2019-12-24 01:16:49

问题


I'm using the MassTransit library's InMemoryMessageBus and I would like to know how I can get the number of messages in the queue (the size of the bus).


回答1:


The number of messages in any particular queue using the in-memory transport is not available. The message delivery is based on a queued task scheduler, and the message counts have not been made available. I'm not sure if they could be or not (well, easily. Anything is possible, but practical is another matter).

UPDATE: This was added to MassTransit and will be in the next release (3.5.x). The tracking issue is on GitHub, including example usage of the new code.




回答2:


If you are using RabbitMQ as your transport, You could use HareDu. The following snippet will get you started:

var client = HareDuFactory.New(x => x.ConnectTo(RabbitMqHostUrl));

var data = client
            .Factory<VirtualHostResources>(y => y.Credentials(RabbitMqUser, RabbitMqPass))
            .Queue
            .GetAll()
            .Data();

foreach (var queue in data)
{
/*then you can access                
queue.Name, queue.VirtualHostName, queue.Memory, queue.Messages,
queue.MessagesReady, queue.MessagesUnacknowledged, queue.Node, queue.IsDurable, queue.Consumers, queue.IdleSince */
}


来源:https://stackoverflow.com/questions/33377354/how-to-get-size-number-of-messages-of-a-masstransit-ibus

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!