简体   繁体   English

如何在特定时间从服务总线获取消息?

[英]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.

相关问题 在 C# 中,如何从 Azure 服务总线队列中获取所有消息? - In C#, How can I get ALL the messages out of an Azure Service Bus Queue? 如何从azure服务总线主题订阅一次接收N条消息 - how to receive N number of messages at time from azure service bus topic subscription 我如何从Windows服务获取用户桌面路径? - How i can get user desktop path from windows services? 如何使用 Telegram API 从 Telegram 频道获取消息 - How can I get messages from a Telegram channel with the Telegram API 如何从互联网获取日期时间到我的特定时区? - How can i get the datetime from the internet to my specific time zone? 如何使Azure Service Bus以FIFO方式工作? - How can I get Azure Service Bus to work in a FIFO manner? 如何按时间间隔有选择地接收 Azure 服务总线消息? - How to selectively receive Azure Service Bus messages by time interval? 每次使用新的guid索引时,如何在集合属性上获取验证消息? - How can I get validation messages to render on collection properties when using new guid indexes each time? 如何以编程方式获取ValidationSummary消息? - How can I get ValidationSummary messages programmatically? 我如何在C#中获取消息? - How can i get messages in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM