This is an add-in for Microsoft.Azure.ServiceBus client
Allows sending messages that exceed maximum size by implementing Claim Check pattern with Azure Storage.
Available here http://nuget.org/packages/ServiceBus.AttachmentPlugin
To Install from the Nuget Package Manager Console
PM> Install-Package ServiceBus.AttachmentPlugin
Configuration and registration
var sender = new MessageSender(connectionString, queueName);
var config = new AzureStorageAttachmentConfiguration(storageConnectionString);
sender.RegisterAzureStorageAttachmentPlugin(config);
Sending
var payload = new MyMessage { ... };
var serialized = JsonConvert.SerializeObject(payload);
var payloadAsBytes = Encoding.UTF8.GetBytes(serialized);
var message = new Message(payloadAsBytes);
Receiving
var receiver = new MessageReceiver(connectionString, entityPath, ReceiveMode.ReceiveAndDelete);
receiver.RegisterAzureStorageAttachmentPlugin(config);
var msg = await receiver.ReceiveAsync().ConfigureAwait(false);
// msg will contain the original payload
Configuration and registration with SAS uri
var sender = new MessageSender(connectionString, queueName);
var config = new AzureStorageAttachmentConfiguration(storageConnectionString)
.WithSasUri(sasTokenValidationTime: TimeSpan.FromHours(4), messagePropertyToIdentifySasUri: "mySasUriProperty");
sender.RegisterAzureStorageAttachmentPlugin(config);
Sending
var payload = new MyMessage { ... };
var serialized = JsonConvert.SerializeObject(payload);
var payloadAsBytes = Encoding.UTF8.GetBytes(serialized);
var message = new Message(payloadAsBytes);
Receive
var receiver = new MessageReceiver(connectionString, entityPath, ReceiveMode.ReceiveAndDelete);
var msg = await receiver.ReceiveAsync().ConfigureAwait(false);
// msg will contain the original payload
Receiving only mode (w/o Storage account credentials)
// Overide message property used to identify SAS URI
// .RegisterAzureStorageAttachmentPluginForReceivingOnly() is using "$attachment.sas.uri" by default
var receiver = messageReceiver.RegisterAzureStorageAttachmentPluginForReceivingOnly("mySasUriProperty");
var msg = await receiver.ReceiveAsync().ConfigureAwait(false);
Default container name is "attachments".
new AzureStorageAttachmentConfiguration(storageConnectionString, containerName:"blobs");
Default blob identifier property name is "$attachment.blob".
new AzureStorageAttachmentConfiguration(storageConnectionString, messagePropertyToIdentifyAttachmentBlob: "myblob");
Default SAS uri property name is "$attachment.sas.uri".
new AzureStorageAttachmentConfiguration(storageConnectionString).WithSasUri(messagePropertyToIdentifySasUri: "mySasUriProperty");
Default is to convert any body to attachment.
// messages with body > 200KB should be converted to use attachments
new AzureStorageAttachmentConfiguration(storageConnectionString, message => message.Body.Length > 200 * 1024);
When Storage connection string needs to be retrieved rather than passed in as a plain text, AzureStorageAttachmentConfiguration
accepts implementation of IProvideStorageConnectionString
.
The plugin comes with a PlainTextConnectionStringProvider
and can be used in the following way.
var provider = new PlainTextConnectionStringProvider("connectionString");
var config = new AzureStorageAttachmentConfiguration(provider);
Proudly list your company here if use this add-in in production
Created by Dinosoft Labs from the Noun Project.