Azure ServiceBus: Client.Receive() returns null fo

2019-08-02 07:26发布

问题:

I'm using a BrokeredMessage containing a Stream with a serialized object. According to the documentation the stream is part of the body not the header which is restricted to 64 KB. The overall message with about 67 KB is well below the limit of 256 KB for the message-size of ServiceBus queues.

  1. I'm able to send a message and it shows up in the queue with the correct message-size.

  2. After issuing the Receive-command the packet is removed from the queue and the counter is decremented accordingly. But, the operation runs into a timeout and returns a null-pointer instead of the BrokeredMessage.

I've tried with a packet with a size of 42 KB and all works well - sending, receiving and deserializing.

Q Why doesn't it work with the larger message and how can I make it work?

Edit 0

I tried receiving a byte-array filled with a random pattern:

var bm = new BrokeredMessage(new byte[n])
  1. n = 63500 does work. (send: HeaderSize = 53, BodySize = 63572; receive: HeaderSize = 139, BodySize = 63572)
  2. n = 64000 does not work. (send: HeaderSize = 54, BodySize = 64072; receive: null)

Edit 1

@David Pfeffer It's just as simple as that:

var queueWork = QueueClient.CreateFromConnectionString(@"Endpoint=sb://***/;SharedAccessKeyName=***;SharedAccessKey=***", path, ReceiveMode.ReceiveAndDelete);
BrokeredMessage message = queueWork.Receive();

回答1:

I am unable to reproduce this. Here's my sample code:

var client = QueueClient.CreateFromConnectionString("Endpoint=sb://***.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=***", "queue", ReceiveMode.ReceiveAndDelete);
client.Send(new BrokeredMessage(new byte[100000]));
var msg = client.Receive();
// msg is happy