MessageReceiver.ReceiveBatch()并不如预期MessageReceiver、ReceiveBatch

由网友(拓土开疆战四方)分享简介:我想用在的messageReceiver的ReceiveBatch方法从ServiceBus收到一批消息:I am trying to receive messages in batch from the ServiceBus using the ReceiveBatch method in the MessageR...

我想用在的messageReceiver的ReceiveBatch方法从ServiceBus收到一批消息:

I am trying to receive messages in batch from the ServiceBus using the ReceiveBatch method in the MessageReceiver:

IEnumerable<BrokeredMessage> messages;
var messagingfactory = MessagingFactory.CreateFromConnectionString("ConnectionString");
var msgrcvr = messagingfactory.CreateMessageReceiver("queueName", ReceiveMode.ReceiveAndDelete);
messages = msgrcvr.ReceiveBatch(20, timeoutInSecs);

我已经检查了我的队列中包含使用服务总线浏览器20的消息。

I have checked that my queue contains 20 messages using the Service Bus Explorer.

这code只返回一个在信息结构的信息。有一些财产,我缺少什么?

This code returns only one message in the messages structure. Is there some property I am missing?

推荐答案

这仅仅是一个局部的答案或解决方法;下面code可靠地获取所有元件,但不使用ReceiveBatch;注意,据我可以看出,皮克(我)的工作在一开始的索引。另外:这取决于服务器的一台正在运行的,如果你是通过邮件拉电,这可能(也可能不会)更昂贵,所以使用您自己的风险:

This is only a partial-answer or work-around; the following code reliably gets all elements, but doesn't use the "ReceiveBatch"; note, as far as I can discern, Peek(i) operates on a one-based index. Also: depending on which server one is running on, if you are charged by the message pull, this may (or may not) be more expensive, so use at your own risk:

        List<BrokeredMessage> dlIE = new List<BrokeredMessage>();

        BrokeredMessage potentialMessage = null;
        int loopCount = 1; 
        while ((potentialMessage = deadletterSubscriptionClient.Peek(loopCount)) != null) 
        { 
             dlIE.Add(potentialMessage); loopCount++; 
        }
阅读全文

相关推荐

最新文章