-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from SeanFeldman/release-2.1.0
Release 2.1.0
- Loading branch information
Showing
15 changed files
with
134 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project> | ||
<PropertyGroup> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/ServiceBus.AttachmentPlugin.Tests/When_using_receive_only_plugin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
| ||
namespace ServiceBus.AttachmentPlugin.Tests | ||
{ | ||
using System; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.ServiceBus; | ||
using Microsoft.Azure.ServiceBus.Core; | ||
using Xunit; | ||
|
||
public class When_using_receive_only_plugin : IClassFixture<AzureStorageEmulatorFixture> | ||
{ | ||
[Fact] | ||
public async Task Should_download_attachment_using_provided_from_sas_uri() | ||
{ | ||
var payload = "payload"; | ||
var bytes = Encoding.UTF8.GetBytes(payload); | ||
var message = new Message(bytes) | ||
{ | ||
MessageId = Guid.NewGuid().ToString(), | ||
}; | ||
var plugin = new AzureStorageAttachment(new AzureStorageAttachmentConfiguration( | ||
connectionString: "UseDevelopmentStorage=true", | ||
containerName: "attachments", | ||
messagePropertyToIdentifyAttachmentBlob: | ||
"attachment-id") | ||
.WithSasUri( | ||
sasTokenValidationTime: TimeSpan.FromHours(4), | ||
messagePropertyToIdentifySasUri: "mySasUriProperty")); | ||
await plugin.BeforeMessageSend(message); | ||
|
||
var messageReceiver = new MessageReceiver(new ServiceBusConnectionStringBuilder( | ||
endpoint: "sb://test.servicebus.windows.net/", | ||
entityPath: "entity", | ||
sharedAccessKey: "---", | ||
sharedAccessKeyName: "RootManageSharedAccessKey")); | ||
messageReceiver.RegisterAzureStorageAttachmentPluginForReceivingOnly("mySasUriProperty"); | ||
var receiveOnlyPlugin = messageReceiver.RegisteredPlugins[0]; | ||
var result = await receiveOnlyPlugin.AfterMessageReceive(message); | ||
|
||
Assert.True(message.UserProperties.ContainsKey("mySasUriProperty")); | ||
Assert.Equal(payload, Encoding.UTF8.GetString(result.Body)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/ServiceBus.AttachmentPlugin/ReceiveOnlyAzureStorageAttachment.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace ServiceBus.AttachmentPlugin | ||
{ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.ServiceBus; | ||
using Microsoft.Azure.ServiceBus.Core; | ||
using Microsoft.WindowsAzure.Storage; | ||
using Microsoft.WindowsAzure.Storage.Blob; | ||
|
||
class ReceiveOnlyAzureStorageAttachment : ServiceBusPlugin | ||
{ | ||
string messagePropertyToIdentifySasUri; | ||
|
||
public ReceiveOnlyAzureStorageAttachment(string messagePropertyToIdentifySasUri) | ||
{ | ||
this.messagePropertyToIdentifySasUri = messagePropertyToIdentifySasUri; | ||
} | ||
|
||
public override string Name { get; } = nameof(ReceiveOnlyAzureStorageAttachment); | ||
|
||
public override async Task<Message> AfterMessageReceive(Message message) | ||
{ | ||
var userProperties = message.UserProperties; | ||
if (!userProperties.ContainsKey(messagePropertyToIdentifySasUri)) | ||
{ | ||
return message; | ||
} | ||
|
||
var blob = new CloudBlockBlob(new Uri(userProperties[messagePropertyToIdentifySasUri].ToString())); | ||
try | ||
{ | ||
await blob.FetchAttributesAsync().ConfigureAwait(false); | ||
} | ||
catch (StorageException exception) | ||
{ | ||
throw new Exception($"Blob with name '{blob.Name}' under container '{blob.Container.Name}' cannot be found.", exception); | ||
} | ||
var fileByteLength = blob.Properties.Length; | ||
var bytes = new byte[fileByteLength]; | ||
await blob.DownloadToByteArrayAsync(bytes, 0).ConfigureAwait(false); | ||
message.Body = bytes; | ||
return message; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters