Service Bus -- .Net AttachmentPlugin to send and receive messages about 1MB

Published 05-30-2021 08:19 PM 1,020 Views
Microsoft

Pre-requirements:

Before we start please read this .Net send and receive Service Bus message , Service Bus message size limit and .Net AttachmentPlugin Simple code.

Following the first document you may understand how to set up a .Net project to send and receive service Bus messages. However, it has limitation for the size of message, Standard pricing tier 256 KB and premium pricing tier 1MB. Then how about the message above 1MB? You may receive an error message about “QuotaExceededException” when your message above the limit. So how to resolve this issue when you need to send message above 1MB?

We plan to release a preview function that allow users send and receive messages up to 100 MB. But currently we don’t have an estimated time. This blog is to explain how to use an AttachmentPlugin in .Net program to send and receive message above 1MB. This is a work around only implement in .Net program. If your system is using other languages like Python, Java and so on, we suggest you separating the messages and change the size of the messages.

Now, let’s talk about how to use this AttachmentPlugin.

Preparation:

The work principle of this AttahchmentPlugin is implement Claim Check pattern with Azure Storage. It based on this pattern to store message data in Azure Storage Account Container (data Store) and pass a Claim Check to Azure Service Bus. Azure Service Bus can use the Claim Check to retrieve the stored information.

Scarlett_liu_0-1622429219958.png

 

  • This Plugin is to save the message to Storage Account, so you need to have an Azure Storage Account first.
  • Then you can get the AttachmentPlugin from Microsoft Visual Studio “Manage Nugget Packages” and search for “ServiceBus.AttachmentPlugin”. Or if you are using Nuget Package Manager Console, you can use this script in below to install it.

           PM> Install-Package ServiceBus.AttachmentPlugin

 vistudio.png

Test:

Parameters :

  • Service Bus Connection String: You can get it from Azure Portal, your Service Bus Namespace “Shared access Policies

servicebusconnectionstring.png

  • Your Service Bus Queue name or Service Bus Topic name and Subscription name
  • Storage Account Connection String: you can get from Azure portal. Check your storage account “Access key”.

storageaccount.png

 

  • And Storage Account Container name.

Program:

After getting all the values, then you can try to use this sample program to send and receive messages.

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using ServiceBus.AttachmentPlugin;

using System.Threading.Tasks;

using Microsoft.Azure.ServiceBus;

using Microsoft.Azure.ServiceBus.Core;

 

namespace ServiceBusAttachmentPlugin

{

    class Program

    {

        const string ServiceBusConnectionString = "<your Service Bus Connection String >";

        const string ServiceBusQueueName = "<your Service Bus Queue name >";

        const string StorageConnectionString = "<your Storage Account Connection String >";

        const string StorageContainerName = "<your Storage Account Container Name>";

        const string ServiceBusTopicName = "<your Service Bus topic name>";

        const string ServiceBusSubscriptionName = "<your Service Bus subscription name>";

       

    private static async Task MainAsync()

    {

            var sender = new MessageSender(ServiceBusConnectionString, ServiceBusQueueName);

            var config = new AzureStorageAttachmentConfiguration(StorageConnectionString, StorageContainerName);

            sender.RegisterAzureStorageAttachmentPlugin(config);

            byte[] msgBytes = Encoding.ASCII.GetBytes("Test message");

            await sender.SendAsync(new Message(msgBytes));

/*If you want to receive message from Service Bus Topic/Subscription, you need to use this EntityNameHelper to get subscriptionPath, then use MessageReceiver() function to receive message .*/

//string subscriptionPath = EntityNameHelper.FormatSubscriptionPath(ServiceBusTopicName, ServiceBusSubscriptionName);

//IMessageReceiver receiver = new MessageReceiver(ServiceBusConnectionString, subscriptionPath, ReceiveMode.ReceiveAndDelete);

            var receiver = new MessageReceiver(ServiceBusConnectionString, ServiceBusQueueName, ReceiveMode.ReceiveAndDelete);

            receiver.RegisterAzureStorageAttachmentPlugin(config);

            var taskrc = await receiver.ReceiveAsync();//Here we use ReceiveAndDelete mode first, if you need use Peeklock mode, please complete the message.

            var message = taskrc.Body;

           // await receiver.CompleteAsync(message.SystemProperties.LockToken);

        }

        static void Main(string[] args)

        {

            MainAsync().GetAwaiter().GetResult();

        }

        }

    }

 

Attentions:

  • You can use your own way to serialize your message, like use function JsonConvert.SerializeObject(). But you need to deserialize the object to your message when you receive it.
  • This sample code use SendAsync() and ReceiveAsync() functions, so we need use “await” to make sure the message complete. For the difference between sync and Async please read my previous blog Service Bus –Complete Message Asynchronously or Synchronously? - Microsoft Tech Community
  • We use RecivedAndDelete mode to receive the message, if you need use PeekLock mode, please remember to complete the message. For example in Microsoft.Azure.ServiceBus use receiver.CompleteAsync(message.SystemProperties.LockToken).Please check Service Bus Receive mode and .Net example  for more examples.

Results:

  • After using the sample code, we sent messages successfully. You can find your message in Azure portal->Service Bus explorer. But it only can Peek 32 messages.

servicebusexploerpng.png

  • You also can check your messages from Service Bus Explorer application, you can download it from GitHub Service Bus Explorer. You can use your Service Bus Connection String to connect your Service Bus. You would get more details about this message.

servicebusexploer2.png

  • In addition, these messages will save to your Storage Account container. You can also check it from your container.

blobmessage.png

In conclusion, this Service Bus AttachmentPlugin is a work around to send and receive messages above 1MB. You need to keep them before you want to receive these messages. And if you received the message from Service Bus the blobs would still in the Azure Storage Account. If you need to delete them when Azure Service Bus receive the message you can add functions to delete it from Storage Account. It would have additional cost in Storage Account, so it would be the limit for this Service Bus AttachmentPlugin.  You can weigh your own interests to make decisions.

2 Comments
Visitor

A couple of clarifications:

1. This plugin is only going to work with the track 1 SDK (Microsoft.Azure.ServiceBus).

2. With the native support of 100MB message size, this plugin will be obsoleted.

Microsoft

Thanks @SeanFeldman 

We are looking forward the release for 100MB message size Service Bus too.  :smile:

%3CLINGO-SUB%20id%3D%22lingo-sub-2399959%22%20slang%3D%22en-US%22%3EService%20Bus%20--%20.Net%20AttachmentPlugin%20to%20send%20and%20receive%20messages%20about%201MB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2399959%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--443075244%22%20id%3D%22toc-hId--443075244%22%20id%3D%22toc-hId--443075244%22%20id%3D%22toc-hId--463115780%22%3E%3CSTRONG%3EPre-requirements%3C%2FSTRONG%3E%3A%3C%2FH2%3E%0A%3CP%3EBefore%20we%20start%20please%20read%20this%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fservice-bus-dotnet-get-started-with-queues%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E.Net%20send%20and%20receive%20Service%20Bus%20message%3C%2FA%3E%3C%2FSPAN%3E%20%2C%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fservice-bus-quotas%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EService%20Bus%20message%20size%20limit%3C%2FA%3E%3C%2FSPAN%3E%20and%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSeanFeldman%2FServiceBus.AttachmentPlugin%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E.Net%20AttachmentPlugin%20Simple%20code%3C%2FA%3E%3C%2FSPAN%3E.%3C%2FP%3E%0A%3CP%3EFollowing%20the%20first%20document%20you%20may%20understand%20how%20to%20set%20up%20a%20%3CSTRONG%3E.Net%20project%3C%2FSTRONG%3E%20to%20send%20and%20receive%20service%20Bus%20messages.%20However%2C%20it%20has%20limitation%20for%20the%20size%20of%20message%2C%20Standard%20pricing%20tier%20%3CSTRONG%3E256%20KB%3C%2FSTRONG%3E%20and%20premium%20pricing%20tier%20%3CSTRONG%3E1MB.%3C%2FSTRONG%3E%20Then%20how%20about%20the%20message%20above%201MB%3F%20You%20may%20receive%20an%20error%20message%20about%20%E2%80%9C%3CSTRONG%3EQuotaExceededException%3C%2FSTRONG%3E%E2%80%9D%20when%20your%20message%20above%20the%20limit.%20So%20how%20to%20resolve%20this%20issue%20when%20you%20need%20to%20send%20message%20above%201MB%3F%3C%2FP%3E%0A%3CP%3EWe%20plan%20to%20release%20a%20preview%20function%20that%20allow%20users%20send%20and%20receive%20messages%20up%20to%20100%20MB.%20But%20currently%20we%20don%E2%80%99t%20have%20an%20%3CSPAN%3Eestimated%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3Etime.%20This%20blog%20is%20to%20explain%20how%20to%20use%20an%20%3CSTRONG%3EAttachmentPlugin%3C%2FSTRONG%3E%20in%20.Net%20program%20to%20%3CSTRONG%3Esend%20and%20receive%20message%20above%201MB%3C%2FSTRONG%3E.%20This%20is%20a%20work%20around%20only%20implement%20in%20.Net%20program.%20If%20your%20system%20is%20using%20other%20languages%20like%20Python%2C%20Java%20and%20so%20on%2C%20we%20suggest%20you%20separating%20the%20messages%20and%20change%20the%20size%20of%20the%20messages.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENow%2C%20%3C%2FSPAN%3E%3CSPAN%3Elet%E2%80%99s%20talk%20about%20how%20to%20use%20this%20%3C%2FSPAN%3EAttachmentPlugin.%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSTRONG%3EPreparation%3C%2FSTRONG%3E%3C%2FSPAN%3E%3CSTRONG%3E%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThe%20work%20principle%20of%20this%20%3CSTRONG%3EAttahchmentPlugin%3C%2FSTRONG%3E%20is%20implement%20%3CSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fwww.enterpriseintegrationpatterns.com%2Fpatterns%2Fmessaging%2FStoreInLibrary.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EClaim%20Check%20pattern%3C%2FA%3E%3C%2FSPAN%3E%26nbsp%3Bwith%20Azure%20Storage.%20It%20based%20on%20this%20pattern%20to%20store%20message%20data%20in%20%3CSTRONG%3EAzure%20Storage%20Account%20Container%3C%2FSTRONG%3E%20(data%20Store)%20and%20pass%20a%26nbsp%3B%3CEM%3EClaim%20Check%3C%2FEM%3E%26nbsp%3Bto%20Azure%20Service%20Bus.%20Azure%20Service%20Bus%20can%20use%20the%26nbsp%3B%3CEM%3EClaim%20Check%3C%2FEM%3E%26nbsp%3Bto%20retrieve%20the%20stored%20information.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Scarlett_liu_0-1622429219958.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F285029i06854BC9C0927194%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Scarlett_liu_0-1622429219958.png%22%20alt%3D%22Scarlett_liu_0-1622429219958.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThis%20Plugin%20is%20to%20save%20the%20message%20to%20Storage%20Account%2C%20so%20you%20need%20to%20have%20%3CSTRONG%3Ean%20Azure%20Storage%20Account%3C%2FSTRONG%3E%20first.%3C%2FLI%3E%0A%3CLI%3EThen%20you%20can%20get%20the%20%3CSTRONG%3EAttachmentPlugin%3C%2FSTRONG%3E%20from%20Microsoft%20Visual%20Studio%20%E2%80%9C%3CSTRONG%3EManage%20Nugget%20Packages%E2%80%9D%20%3C%2FSTRONG%3Eand%20search%20for%20%E2%80%9C%3CSTRONG%3EServiceBus.AttachmentPlugin%3C%2FSTRONG%3E%E2%80%9D.%20Or%20if%20you%20are%20using%20Nuget%20Package%20Manager%20Console%2C%20you%20can%20use%20this%20script%20in%20below%20to%20install%20it.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3BPM%26gt%3B%20Install-Package%20ServiceBus.AttachmentPlugin%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22vistudio.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F285036i744BFA9A64622FC4%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22vistudio.png%22%20alt%3D%22vistudio.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-2044437589%22%20id%3D%22toc-hId-2044437589%22%20id%3D%22toc-hId-2044437589%22%20id%3D%22toc-hId-2024397053%22%3E%3CSTRONG%3ETest%3A%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CH3%20id%3D%22toc-hId--1559968233%22%20id%3D%22toc-hId--1559968233%22%20id%3D%22toc-hId--1559968233%22%20id%3D%22toc-hId--1580008769%22%3E%3CEM%3EParameters%20%3A%3C%2FEM%3E%3C%2FH3%3E%0A%3CUL%3E%0A%3CLI%3EService%20Bus%20Connection%20String%3A%20You%20can%20get%20it%20from%20Azure%20Portal%2C%20your%20Service%20Bus%20Namespace%20%E2%80%9C%3CSTRONG%3EShared%20access%20Policies%3C%2FSTRONG%3E%E2%80%9D%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusconnectionstring.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F285035iBA592B105FFFF271%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22servicebusconnectionstring.png%22%20alt%3D%22servicebusconnectionstring.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EYour%20Service%20Bus%20Queue%20name%20or%20Service%20Bus%20Topic%20name%20and%20Subscription%20name%3C%2FLI%3E%0A%3CLI%3EStorage%20Account%20Connection%20String%3A%20you%20can%20get%20from%20Azure%20portal.%20Check%20your%20storage%20account%20%3CSTRONG%3E%E2%80%9CAccess%20key%E2%80%9D.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22storageaccount.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F285034iB887ACCF6AD66C65%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22storageaccount.png%22%20alt%3D%22storageaccount.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EAnd%20Storage%20Account%20Container%20name.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH3%20id%3D%22toc-hId-927544600%22%20id%3D%22toc-hId-927544600%22%20id%3D%22toc-hId-927544600%22%20id%3D%22toc-hId-907504064%22%3E%3CEM%3EProgram%3C%2FEM%3E%3A%3C%2FH3%3E%0A%3CP%3EAfter%20getting%20all%20the%20values%2C%20then%20you%20can%20try%20to%20use%20this%20sample%20program%20to%20send%20and%20receive%20messages.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eusing%20System%3B%3C%2FP%3E%0A%3CP%3Eusing%20System.Collections.Generic%3B%3C%2FP%3E%0A%3CP%3Eusing%20System.Linq%3B%3C%2FP%3E%0A%3CP%3Eusing%20System.Text%3B%3C%2FP%3E%0A%3CP%3Eusing%20ServiceBus.AttachmentPlugin%3B%3C%2FP%3E%0A%3CP%3Eusing%20System.Threading.Tasks%3B%3C%2FP%3E%0A%3CP%3Eusing%20Microsoft.Azure.ServiceBus%3B%3C%2FP%3E%0A%3CP%3Eusing%20Microsoft.Azure.ServiceBus.Core%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Enamespace%20ServiceBusAttachmentPlugin%3C%2FP%3E%0A%3CP%3E%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20class%20Program%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20const%20string%20ServiceBusConnectionString%20%3D%20%22%3CYOUR%20service%3D%22%22%20bus%3D%22%22%20connection%3D%22%22%20string%3D%22%22%3E%22%3B%3C%2FYOUR%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20const%20string%20ServiceBusQueueName%20%3D%20%22%3CYOUR%20service%3D%22%22%20bus%3D%22%22%20queue%3D%22%22%20name%3D%22%22%3E%22%3B%3C%2FYOUR%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20const%20string%20StorageConnectionString%20%3D%20%22%3CYOUR%20storage%3D%22%22%20account%3D%22%22%20connection%3D%22%22%20string%3D%22%22%3E%22%3B%3C%2FYOUR%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20const%20string%20StorageContainerName%20%3D%20%22%3CYOUR%20storage%3D%22%22%20account%3D%22%22%20container%3D%22%22%20name%3D%22%22%3E%22%3B%3C%2FYOUR%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20const%20string%20ServiceBusTopicName%20%3D%20%22%3CYOUR%20service%3D%22%22%20bus%3D%22%22%20topic%3D%22%22%20name%3D%22%22%3E%22%3B%3C%2FYOUR%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20const%20string%20ServiceBusSubscriptionName%20%3D%20%22%3CYOUR%20service%3D%22%22%20bus%3D%22%22%20subscription%3D%22%22%20name%3D%22%22%3E%22%3B%3C%2FYOUR%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%26nbsp%3Bprivate%20static%20async%20Task%20MainAsync()%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20sender%20%3D%20new%20MessageSender(ServiceBusConnectionString%2C%20ServiceBusQueueName)%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20config%20%3D%20new%20AzureStorageAttachmentConfiguration(StorageConnectionString%2C%20StorageContainerName)%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sender.RegisterAzureStorageAttachmentPlugin(config)%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20byte%5B%5D%20msgBytes%20%3D%20Encoding.ASCII.GetBytes(%22Test%20message%22)%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20await%20sender.SendAsync(new%20Message(msgBytes))%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23339966%22%3E%2F*If%20you%20want%20to%20receive%20message%20from%20Service%20Bus%20Topic%2FSubscription%2C%20you%20need%20to%20use%20this%20EntityNameHelper%20to%20get%20subscriptionPath%2C%20then%20use%20MessageReceiver()%20function%20to%20receive%20message%20.*%2F%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23339966%22%3E%2F%2Fstring%20subscriptionPath%20%3D%20EntityNameHelper.FormatSubscriptionPath(ServiceBusTopicName%2C%20ServiceBusSubscriptionName)%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%3CFONT%20color%3D%22%23339966%22%3E%2F%2FIMessageReceiver%20receiver%20%3D%20new%20MessageReceiver(ServiceBusConnectionString%2C%20subscriptionPath%2C%20ReceiveMode.ReceiveAndDelete)%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20receiver%20%3D%20new%20MessageReceiver(ServiceBusConnectionString%2C%20ServiceBusQueueName%2C%20ReceiveMode.ReceiveAndDelete)%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20receiver.RegisterAzureStorageAttachmentPlugin(config)%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20taskrc%20%3D%20await%20receiver.ReceiveAsync()%3B%3CFONT%20color%3D%22%23339966%22%3E%2F%2FHere%20we%20use%20%3CSTRONG%3EReceiveAndDelete%3C%2FSTRONG%3E%20mode%20first%2C%20if%20you%20need%20use%20%3CSTRONG%3EPeeklock%3C%2FSTRONG%3E%20mode%2C%20please%20complete%20the%20message.%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20var%20message%20%3D%20taskrc.Body%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CFONT%20color%3D%22%23339966%22%3E%20%2F%2F%20await%20receiver.CompleteAsync(message.SystemProperties.LockToken)%3B%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20static%20void%20Main(string%5B%5D%20args)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20MainAsync().GetAwaiter().GetResult()%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--879909863%22%20id%3D%22toc-hId--879909863%22%20id%3D%22toc-hId--879909863%22%20id%3D%22toc-hId--899950399%22%3E%3CEM%3EAttentions%3C%2FEM%3E%3A%3C%2FH3%3E%0A%3CUL%3E%0A%3CLI%3EYou%20can%20use%20your%20own%20way%20to%20serialize%20your%20message%2C%20like%20use%20function%20JsonConvert.SerializeObject().%20But%20you%20need%20to%20deserialize%20the%20object%20to%20your%20message%20when%20you%20receive%20it.%3C%2FLI%3E%0A%3CLI%3EThis%20sample%20code%20use%20SendAsync()%20and%20ReceiveAsync()%20functions%2C%20so%20we%20need%20use%20%E2%80%9C%3CSTRONG%3Eawait%E2%80%9D%3C%2FSTRONG%3E%20to%20make%20sure%20the%20message%20complete.%20For%20the%20difference%20between%20sync%20and%20Async%20please%20read%20my%20previous%20blog%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-paas-blog%2Fservice-bus-complete-message-asynchronously-or-synchronously%2Fba-p%2F2073742%22%20target%3D%22_blank%22%3EService%20Bus%20%E2%80%93Complete%20Message%20Asynchronously%20or%20Synchronously%3F%20-%20Microsoft%20Tech%20Community%3C%2FA%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3CLI%3EWe%20use%20%3CSTRONG%3ERecivedAndDelete%3C%2FSTRONG%3E%20mode%20to%20receive%20the%20message%2C%20if%20you%20need%20use%20%3CSTRONG%3EPeekLock%3C%2FSTRONG%3E%20mode%2C%20please%20remember%20to%20complete%20the%20message.%20For%20example%20in%20Microsoft.Azure.ServiceBus%20use%20%3CEM%3Ereceiver.CompleteAsync(message.SystemProperties.LockToken).%3C%2FEM%3EPlease%20check%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fservice-bus-performance-improvements%3Ftabs%3Dnet-standard-sdk%23receive-mode%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EService%20Bus%20Receive%20mode%20and%20.Net%20example%3C%2FA%3E%3C%2FSPAN%3E%26nbsp%3B%20for%20more%20examples.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId--890412967%22%20id%3D%22toc-hId--890412967%22%20id%3D%22toc-hId--890412967%22%20id%3D%22toc-hId--910453503%22%3E%3CSTRONG%3EResults%3C%2FSTRONG%3E%3A%3C%2FH2%3E%0A%3CUL%3E%0A%3CLI%3EAfter%20using%20the%20sample%20code%2C%20we%20sent%20messages%20successfully.%20You%20can%20find%20your%20message%20in%20Azure%20portal-%26gt%3BService%20Bus%20explorer.%20But%20it%20only%20can%20Peek%2032%20messages.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusexploerpng.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F285037i105A632579B465E5%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22servicebusexploerpng.png%22%20alt%3D%22servicebusexploerpng.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EYou%20also%20can%20check%20your%20messages%20from%20Service%20Bus%20Explorer%20application%2C%20you%20can%20download%20it%20from%20%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fpaolosalvatori%2FServiceBusExplorer%2Freleases%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGitHub%20Service%20Bus%20Explorer%3C%2FA%3E%3C%2FSPAN%3E.%20You%20can%20use%20your%20Service%20Bus%20Connection%20String%20to%20connect%20your%20Service%20Bus.%20You%20would%20get%20more%20details%20about%20this%20message.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22servicebusexploer2.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F285038iFDCA25842E208EAE%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22servicebusexploer2.png%22%20alt%3D%22servicebusexploer2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIn%20addition%2C%20these%20messages%20will%20save%20to%20your%20Storage%20Account%20container.%20You%20can%20also%20check%20it%20from%20your%20container.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22blobmessage.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F285040i5EB03302D87ECD40%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22blobmessage.png%22%20alt%3D%22blobmessage.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EIn%20conclusion%2C%20this%20%3CSTRONG%3EService%20Bus%20AttachmentPlugin%3C%2FSTRONG%3E%20is%20a%20work%20around%20to%20send%20and%20receive%20messages%20above%201MB.%20You%20need%20to%20keep%20them%20before%20you%20want%20to%20receive%20these%20messages.%20And%20if%20you%20received%20the%20message%20from%20Service%20Bus%20the%20blobs%20would%20still%20in%20the%20Azure%20Storage%20Account.%20If%20you%20need%20to%20delete%20them%20when%20Azure%20Service%20Bus%20receive%20the%20message%20you%20can%20add%20functions%20to%20delete%20it%20from%20Storage%20Account.%20It%20would%20have%20%3CSTRONG%3Eadditional%3C%2FSTRONG%3E%20%3CSTRONG%3Ecost%3C%2FSTRONG%3E%20in%20Storage%20Account%2C%20so%20it%20would%20be%20the%20limit%20for%20this%20Service%20Bus%20AttachmentPlugin.%26nbsp%3B%20You%20can%20weigh%20your%20own%20interests%20to%20make%20decisions.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2399959%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20understand%20how%20to%20set%20up%20a%20.Net%20project%20to%20send%20and%20receive%20service%20Bus%20messages.%20However%2C%20it%20has%20%3CSTRONG%3Elimitation%3C%2FSTRONG%3E%20for%20the%20size%20of%20message%2C%20Standard%20pricing%20tier%20%3CSTRONG%3E256%20KB%3C%2FSTRONG%3E%20and%20premium%20pricing%20tier%20%3CSTRONG%3E1MB%3C%2FSTRONG%3E.%20Then%20how%20about%20the%20message%20%3CSTRONG%3Eabove%201MB%3C%2FSTRONG%3E%3F%20You%20may%20receive%20an%20error%20message%20about%20%E2%80%9C%3CSTRONG%3EQuotaExceededException%3C%2FSTRONG%3E%E2%80%9D%20when%20your%20message%20above%20the%20limit.%20So%20how%20to%20resolve%20this%20issue%20when%20you%20need%20to%20send%20message%20above%201MB%3F%3C%2FP%3E%0A%3CP%3EWe%20plan%20to%20release%20a%20preview%20function%20that%20allow%20users%20send%20and%20receive%20messages%20up%20to%20100%20MB.%20But%20currently%20we%20don%E2%80%99t%20have%20an%20%3CSPAN%3Eestimated%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3Etime.%20This%20blog%20is%20to%20explain%20how%20to%20use%20an%20%3CSTRONG%3EAttachmentPlugin%3C%2FSTRONG%3E%20in%3CSTRONG%3E%20.Net%20program%3C%2FSTRONG%3E%20to%20send%20and%20receive%20message%20above%201MB.%20This%20is%20a%20work%20around%20only%20implement%20in%20.Net%20program.%20If%20your%20system%20is%20using%20other%20languages%20like%20Python%2C%20Java%20and%20so%20on%2C%20we%20suggest%20you%20separating%20the%20messages%20and%20change%20the%20size%20of%20the%20messages.%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENow%2C%20%3C%2FSPAN%3E%3CSPAN%3Elet%E2%80%99s%20talk%20about%20how%20to%20use%20this%20%3C%2FSPAN%3EAttachmentPlugin.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2399959%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Service%20Bus%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2401467%22%20slang%3D%22en-US%22%3ERe%3A%20Service%20Bus%20--%20.Net%20AttachmentPlugin%20to%20send%20and%20receive%20messages%20about%201MB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2401467%22%20slang%3D%22en-US%22%3E%3CP%3EA%20couple%20of%20clarifications%3A%3C%2FP%3E%3CP%3E1.%20This%20plugin%20is%20only%20going%20to%20work%20with%20the%20track%201%20SDK%20(Microsoft.Azure.ServiceBus).%3C%2FP%3E%3CP%3E2.%20With%20the%20native%20support%20of%20100MB%20message%20size%2C%20this%20plugin%20will%20be%20obsoleted.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎May 30 2021 08:16 PM
Updated by: