Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding multiple elements to Azure Queue in a single message

Tags:

c#

cloud

azure

I'm interacting with an AzureStorageAccount with CloudQueueClient similarly to the manner described in this msdn example

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("some connection string");
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

and to add an element to a queue (with some boiler plate removed):

var queue = queueClient.GetQueueReference("queuename");
var message = new CloudQueueMessage("myString");
queue.AddMessageAsync(message);

So that means I can add "myString" to my queue. Great. And if I repeatedly call those lines of code I can add "mystring" lots of time. Also good, but inefficient.

How do I add multiple items to the queue in one message?

I've researched this a bit and found Entity Group Transactions, which may be a suitable fit. However, this looks very different to what I've been doing and don't really give me any code examples. Is there any way to use this and continue to use Microsoft.WindowsAzure.StorageClient libary to construct my messages?

like image 600
Nathan Cooper Avatar asked May 15 '14 11:05

Nathan Cooper


People also ask

What is the size of a single message in a azure queue?

A single queue message can be up to 64 KB in size, and a queue can contain millions of messages, up to the total capacity limit of a storage account.

What is the maximum size of a single queue message in azure queue storage?

A queue message can be up to 64 KB in size. A queue may contain millions of messages, up to the total capacity limit of a storage account.

What is the difference between azure storage queue and service bus queue?

Storage Queue is a simple message queuing service to store large numbers of messages. Service Bus Queue is part of a broader messaging service that supports queuing, publish/subscribe, and more advanced integration patterns.


1 Answers

One way you can send multiple messages is to build a wrapper class that contains a list of individual string values (or objects), serialize this into a JSon object for example, and send that as the payload for the message. The issue here is that depending on the size of your objects, you could eventually exceed the size limitation of a message. So that's not a recommended implemtation.

At some point I was dealing with a system that needed to send a lot of messages per second; it was massively distributed. Instead of batching multiple messages we ended up creating a shard of message queues, across multiple storage accounts. The scalability requirements drove us to this implementation.

Keep in mind that Chunky vs Chatty applies to sending more information in order to avoid roundtrips, so as to optimize performance. Message queuing is not as much about performance; it is more about scalability and distribution of information. In other words, eventual consistency and distributed scale out are the patterns to favor in this environment. I am not saying you should ignore chunky vs chatty, but you should apply it where it makes sense.

If you need to send 1 million messages per second for example, then chunkier calls is an option; sharding is another. I typically favor sharding because there are fewer scalability boundaries. But in some cases, if the problem is simple enough, chunking might suffice.

like image 66
Herve Roggero Avatar answered Sep 22 '22 01:09

Herve Roggero