Azure的ServiceBus上Client.Receive返回null() [英] Azure ServiceBus returns null on Client.Receive()

查看:234
本文介绍了Azure的ServiceBus上Client.Receive返回null()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有从我所蔚蓝中设立了一个队列接收消息的问题。
我这样做成功使用前相同的code,但现在我只是得到空当我尝试获取信息。
当我查看Azure管理控制台中的队列我清楚地看到队列包含5的消息。

I have a problem with receiving messages from a queue i have set up in azure. I have done this successfully using the same code before but now i just get null when i try to fetch messages. When i view the queue in azure management console i clearly see that the queue contains 5 messages.

下面是code:

ServiceBus SB = new ServiceBus();
Microsoft.ServiceBus.Messaging.BrokeredMessage message;
while (true)
{
    message = SB.ReceiveMessage("orders");
    if (message == null)
    {
        break;
    }
    Procurement.Order order = message.GetBody<Procurement.Order>();
    order.id = Guid.NewGuid().ToString();
    order.remindercount = 0;

    using (DbManager db = new DbManager())
    {
        if (db.SetSpCommand("CreateOrderHead",
            db.Parameter("@companyId", order.companyId),
            db.Parameter("@orderId", order.orderId),
            db.Parameter("@suppliercode", order.suppliercode),
            db.Parameter("@supplierorderId", order.supplierorderId),
            db.Parameter("@orderdate", order.orderdate),
            db.Parameter("@desireddate", order.desireddate),
            db.Parameter("@ordertext", order.ordertext),
            db.Parameter("@name", order.name),
            db.Parameter("@street", order.street),
            db.Parameter("@zip", order.zip),
            db.Parameter("@city", order.city),
            db.Parameter("@country", order.country),
            db.Parameter("@countrycode", order.countrycode),
            db.Parameter("@deliveryterms", order.deliveryterms),
            db.Parameter("@reference", order.reference),
            db.Parameter("@deliveryinstruction", order.deliveryinstruction),
            db.Parameter("@id", order.id),
            db.Parameter("@partycode", order.partyCode)
            ).ExecuteNonQuery() == 1)
        {
            message.Complete();
            message = null;
        }

        db.SetSpCommand("DeleteOrderRows",
            db.Parameter("@orderid", order.orderId),
            db.Parameter("@companyId", order.companyId)
            ).ExecuteNonQuery();

        foreach (Procurement.Orderrow r in order.Orderrows)
        {
            db.SetSpCommand("CreateOrderRow",
            db.Parameter("@companyId", r.companyId),
            db.Parameter("@orderId", r.orderId),
            db.Parameter("@orderrowId", r.orderrowId),
            db.Parameter("@itemId", r.itemId),
            db.Parameter("@itemdesc", r.itemdesc),
            db.Parameter("@orderqty", r.orderqty),
            db.Parameter("@desireddate", r.desireddate),
            db.Parameter("@rowtext", r.rowtext),
            db.Parameter("@supplieritemId", r.supplieritemId),
            db.Parameter("@unit", r.unit),
            db.Parameter("@id", order.id),
            db.Parameter("@unitprice", r.unitprice),
            db.Parameter("@rowprice", r.rowprice)
            ).ExecuteNonQuery();
        }
    }
}
Thread.Sleep(new TimeSpan(0, 1, 0));

这是ServiceBus类:

And this is the ServiceBus-class:

public class ServiceBus
{
    TokenProvider TokenProvider;
    MessagingFactory Factory;

    public ServiceBus()
    {
        TokenProvider = TokenProvider.CreateSharedSecretTokenProvider(GetIssuerName(), GetSecret());
        Factory = MessagingFactory.Create(
            GetURINameSpace(),
            TokenProvider
            );
    }

    public void SendMessage(string queue, BrokeredMessage message)
    {
        var client = Factory.CreateQueueClient(queue);
        client.Send(message);
    }

    public BrokeredMessage ReceiveMessage(string queue)
    {
        var client = Factory.CreateQueueClient(queue, ReceiveMode.ReceiveAndDelete);
        BrokeredMessage message = client.Receive();
        return message;
    }

    private static Uri GetURINameSpace()
    {
        return ServiceBusEnvironment.CreateServiceUri("sb", GetNamespace(), string.Empty);
    }

    private static string GetNamespace()
    {
        return "Namespace i have verified its the right one";
    }

    private static string GetIssuerName()
    {
        return "Issuer i have verified its the right one";
    }

    private static string GetSecret()
    {
        return "Key i have verified its the right one";
    }
}

我想这应该是pretty直线前进,但我不能找出什么即时通讯做错了。
它可能是一些小的,即时通讯失踪......

I think this should be pretty straight forward but i cant find out what im doing wrong. Its probably something small that im missing...

不管怎样,先谢谢了!

推荐答案

要解决这个问题要么在Azure管理门户中的错误使得它显示了错误的号码在队列中的消息或以某种方式的消息得到了标记,从而他们不会被读取。
在这一切的工作一起换句话说,我刚刚有了一些新的消息添加到队列中。

The solution to this problem was either a bug in azure management-portal making it show the wrong number of messages on the queue or the messages somehow got flagged so that they would not be read. In other words it worked all along, i just had to add some new messages to the queue.

这篇关于Azure的ServiceBus上Client.Receive返回null()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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