MessageReceiver.ReceiveBatch()并不如预期 [英] MessageReceiver.ReceiveBatch() not working as intended

查看:128
本文介绍了MessageReceiver.ReceiveBatch()并不如预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用在的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++; 
        }

这篇关于MessageReceiver.ReceiveBatch()并不如预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆