[英]How can I get messages from Services Bus in a specific time?
I have this method that works great to get all the messages from my subscription in Azure Service Bus.我有这个方法可以很好地从 Azure 服务总线中的订阅中获取所有消息。 But I want the messages that have been in there for the last 60 minutes.
但我想要过去 60 分钟内一直存在的消息。 Is there a way to do that?
有没有办法做到这一点?
public void GetMessages()
{
var connectionString = ConfigurationManager.ConnectionStrings["ServiceBus.EndPoint"].ConnectionString;
var topic = ConfigurationManager.AppSettings["ServiceBus.Topic"];
var subscription = ConfigurationManager.AppSettings["ServiceBus.Subscription"];
var client = SubscriptionClient.CreateFromConnectionString(connectionString, topic, subscription, ReceiveMode.PeekLock);
client.RetryPolicy = new RetryExponential(TimeSpan.FromSeconds(0.1), TimeSpan.FromSeconds(5), 5);
var messages = client.PeekBatch(100);
foreach (var msg in messages)
{
string body = msg.GetBody<String>();
}
}
I want the messages that have been in there for the last 60 minutes
我想要过去 60 分钟内的消息
The short answer is "why?".简短的回答是“为什么?”。 You can peek at the messages, but when you'll try to get them, you're not promised to have the same messages.
您可以偷看这些消息,但是当您尝试获取它们时,您不会得到相同的消息。 Or any messages at all.
或任何消息。
It's been said by many multiple times that a happy queue is an empty queue.很多人说过,快乐的队列是空的队列。 If a message is sitting on a queue for 60 minutes, then something feels off.
如果一条消息在队列中停留了 60 分钟,那么就会感觉有些不对劲。 Almost as if a queue is used as a storage.
几乎就像使用队列作为存储一样。 Either your processors where all offline, and once they get online they should process regardless of how long the message was on the queue, or you're looking for some functionality that probably should be implemented via additional service/in a different way.
要么您的处理器全部离线,并且一旦它们上线,无论消息在队列中多长时间,它们都应该处理,或者您正在寻找一些可能应该通过附加服务/以不同方式实现的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.