0
votes

I am tring to store File byte[] to Azure ServiceBusQueue and read it back from Queue.

Here is my code to store file to queue.

var uploadedFile = new Byte[FileUpload1.PostedFile.InputStream.Length]; 

            FileUpload1.PostedFile.InputStream.Read(uploadedFile, 0, FileUpload1.PostedFile.ContentLength);

            var message = Utility.CreateBrokeredMessage(uploadedFile);


            var senderQueue = new QueueSender("tasksnotifications");

            if (senderQueue.SendMessage(message))
            {
                ResultText = "Your message has been submitted successfully";
                MessageTextBox.Text = string.Empty;
            }
            else
            {
                ResultText = "Your message is not submitted.";
            }

And Here is code for reading message from Queue.

// Process message from queue
             Console.WriteLine("Body: " + messageReceivedEventArgs.BrokeredMessage.GetBody<object>());

             Console.WriteLine("MessageID: " + messageReceivedEventArgs.BrokeredMessage.MessageId);

             // Remove message from queue
             messageReceivedEventArgs.BrokeredMessage.Complete();

I am not sure if it is possible to store byte[] of file to Azure ServiceBus Queue, but the data is sent successfully.

Questions: How do I read byte[] from BrokeredMessage object which I received from Queue?

Please share any useful links with this topic or if this question is already asked somewhere.

Thanks.

1

1 Answers

1
votes

You should be to accomplish this by deserializing the message body as a byte[]:

// Process message from queue
Console.WriteLine("Body: " + messageReceivedEventArgs.BrokeredMessage.GetBody<byte[]>());

Note that the maximum size of a Service Bus message is 256 KB. See also Service Bus Quotas.