├── sign.snk
├── webjobs.png
├── test
└── Microsoft.Azure.WebJobs.Extensions.ServiceBus.Tests
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── ServiceBusAttributeTests.cs
│ ├── PublicSurfaceTests.cs
│ ├── Bindings
│ ├── BoundServiceBusTests.cs
│ ├── ParameterizedServiceBusPathTests.cs
│ ├── BindableServiceBusPathTests.cs
│ ├── ServiceBusAttributeBindingProviderTests.cs
│ └── ServiceBusTriggerAttributeBindingProviderTests.cs
│ ├── MessageToByteArrayConverterTests.cs
│ ├── ServiceBusTriggerAttributeTests.cs
│ ├── WebJobs.Extensions.ServiceBus.Tests.csproj
│ ├── README.md
│ ├── MessageProcessorTests.cs
│ ├── ServiceBusAccountTests.cs
│ ├── MessagingProviderTests.cs
│ ├── MessageToStringConverterTests.cs
│ ├── Config
│ ├── ServiceBusHostBuilderExtensionsTests.cs
│ └── ServiceBusOptionsTests.cs
│ └── Listeners
│ └── ServiceBusListenerTests.cs
├── NuGet.Config
├── src
└── Microsoft.Azure.WebJobs.Extensions.ServiceBus
│ ├── Bindings
│ ├── IQueueArgumentBindingProvider.cs
│ ├── ServiceBusParameterDescriptor.cs
│ ├── MessageArgumentBindingProvider.cs
│ ├── ServiceBusEntity.cs
│ ├── UserTypeToBrokeredMessageConverter.cs
│ ├── ByteArrayToBrokeredMessageConverter.cs
│ ├── StringToBrokeredMessageConverter.cs
│ ├── MessageSenderExtensions.cs
│ ├── IBindableServiceBusPath.cs
│ ├── CompositeArgumentBindingProvider.cs
│ ├── BoundServiceBusPath.cs
│ ├── CollectorValueProvider.cs
│ ├── OutputConverter.cs
│ ├── MessageConverterFactory.cs
│ ├── MessageSenderCollector.cs
│ ├── BindableServiceBusPath.cs
│ ├── ConverterValueBinder.cs
│ ├── ParameterizedServiceBusPath.cs
│ ├── MessageSenderAsyncCollector.cs
│ ├── StringToServiceBusEntityConverter.cs
│ ├── NonNullConverterValueBinder.cs
│ ├── StringArgumentBindingProvider.cs
│ ├── ByteArrayArgumentBindingProvider.cs
│ ├── UserTypeArgumentBindingProvider.cs
│ ├── MessageSenderArgumentBindingProvider.cs
│ ├── CollectorArgumentBindingProvider.cs
│ ├── AsyncCollectorArgumentBindingProvider.cs
│ ├── MessageArgumentBinding.cs
│ ├── ServiceBusBinding.cs
│ └── ServiceBusAttributeBindingProvider.cs
│ ├── ContentTypes.cs
│ ├── EntityType.cs
│ ├── StrictEncodings.cs
│ ├── ServiceBusWebJobsStartup.cs
│ ├── Utility.cs
│ ├── Triggers
│ ├── MessageToByteArrayConverter.cs
│ ├── OutputConverter.cs
│ ├── MessageToStringConverter.cs
│ ├── MessageToPocoConverter.cs
│ ├── ServiceBusTriggerInput.cs
│ └── ServiceBusTriggerAttributeBindingProvider.cs
│ ├── Config
│ ├── BatchOptions.cs
│ ├── ServiceBusWebJobsBuilderExtensions.cs
│ ├── ServiceBusExtensionConfigProvider.cs
│ └── ServiceBusOptions.cs
│ ├── Listeners
│ ├── ServiceBusTriggerMetrics.cs
│ ├── ServiceBusEntityPathHelper.cs
│ ├── ServiceBusCausalityHelper.cs
│ └── ServiceBusListenerFactory.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ ├── GlobalSuppressions.cs
│ ├── Constants.cs
│ ├── ServiceBusAccount.cs
│ ├── ServiceBusAccountAttribute.cs
│ ├── WebJobs.Extensions.ServiceBus.csproj
│ ├── ServiceBusAttribute.cs
│ ├── SessionMessageProcessor.cs
│ ├── MessageProcessor.cs
│ └── ServiceBusTriggerAttribute.cs
├── release_notes.md
├── .github
└── pull_request_template.md
├── stylecop.json
├── LICENSE.txt
├── README.md
├── ServiceBusExtension.sln
├── SECURITY.md
├── src.ruleset
└── .gitignore
/sign.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure/azure-functions-servicebus-extension/HEAD/sign.snk
--------------------------------------------------------------------------------
/webjobs.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Azure/azure-functions-servicebus-extension/HEAD/webjobs.png
--------------------------------------------------------------------------------
/test/Microsoft.Azure.WebJobs.Extensions.ServiceBus.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System.Reflection;
5 | using Xunit;
6 |
7 | [assembly: CollectionBehavior(CollectionBehavior.CollectionPerAssembly)]
--------------------------------------------------------------------------------
/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/IQueueArgumentBindingProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System.Reflection;
5 | using Microsoft.Azure.WebJobs.Host.Bindings;
6 |
7 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
8 | {
9 | internal interface IQueueArgumentBindingProvider
10 | {
11 | IArgumentBinding TryCreate(ParameterInfo parameter);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/ContentTypes.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.Azure.WebJobs.ServiceBus
5 | {
6 | internal static class ContentTypes
7 | {
8 | public const string TextPlain = "text/plain";
9 |
10 | public const string ApplicationJson = "application/json";
11 |
12 | public const string ApplicationOctetStream = "application/octet-stream";
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/ServiceBusParameterDescriptor.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using Microsoft.Azure.WebJobs.Host.Protocols;
5 |
6 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
7 | {
8 | internal class ServiceBusParameterDescriptor : ParameterDescriptor
9 | {
10 | /// Gets or sets the name of the queue or topic.
11 | public string QueueOrTopicName { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/release_notes.md:
--------------------------------------------------------------------------------
1 | ### Release notes
2 |
5 | #### Version Version 4.3.1
6 | - Add listener details (#186)
7 | - Fix batch receive race condition (#184)
8 | - ServiceBusTrigger should allow for binding the MessageReceiver instance by interface (#69)
9 |
10 | #### Version Version 4.3.0
11 | - Added support for allowing 'autoComplete' setting at the function level for all the single, batch or session triggers.
12 |
13 |
14 | **Release sprint:** Sprint 100
15 | [ [features](https://github.com/Azure/azure-functions-servicebus-extension/issues/138) ]
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/EntityType.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | namespace Microsoft.Azure.WebJobs.ServiceBus
5 | {
6 | ///
7 | /// Service Bus entity type.
8 | ///
9 | public enum EntityType
10 | {
11 | ///
12 | /// Service Bus Queue
13 | ///
14 | Queue,
15 |
16 | ///
17 | /// Service Bus Topic
18 | ///
19 | Topic
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/StrictEncodings.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System.Text;
5 |
6 | namespace Microsoft.Azure.WebJobs.ServiceBus
7 | {
8 | internal static class StrictEncodings
9 | {
10 | private static UTF8Encoding _utf8 = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false,
11 | throwOnInvalidBytes: true);
12 |
13 | public static UTF8Encoding Utf8
14 | {
15 | get { return _utf8; }
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/test/Microsoft.Azure.WebJobs.Extensions.ServiceBus.Tests/ServiceBusAttributeTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using Xunit;
5 |
6 | namespace Microsoft.Azure.WebJobs.ServiceBus.UnitTests
7 | {
8 | public class ServiceBusAttributeTests
9 | {
10 | [Fact]
11 | public void Constructor_Success()
12 | {
13 | ServiceBusAttribute attribute = new ServiceBusAttribute("testqueue");
14 | Assert.Equal("testqueue", attribute.QueueOrTopicName);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/ServiceBusWebJobsStartup.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using Microsoft.Azure.WebJobs.ServiceBus;
5 | using Microsoft.Azure.WebJobs.Hosting;
6 | using Microsoft.Extensions.Hosting;
7 |
8 | [assembly: WebJobsStartup(typeof(ServiceBusWebJobsStartup))]
9 |
10 | namespace Microsoft.Azure.WebJobs.ServiceBus
11 | {
12 | public class ServiceBusWebJobsStartup : IWebJobsStartup
13 | {
14 | public void Configure(IWebJobsBuilder builder)
15 | {
16 | builder.AddServiceBus();
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ### Issue describing the changes in this PR
4 |
5 | resolves #issue_for_this_pr
6 |
7 | ### Pull request checklist
8 |
9 | * [ ] My changes **do not** require documentation changes
10 | * [ ] Otherwise: Documentation issue linked to PR
11 | * [ ] My changes **should not** be added to the release notes for the next release
12 | * [ ] Otherwise: I've added my notes to `release_notes.md`
13 | * [ ] My changes **do not** need to be backported to a previous version
14 | * [ ] Otherwise: Backport tracked by issue/PR #issue_or_pr
15 | * [ ] I have added all required tests (Unit tests, E2E tests)
16 |
17 |
18 | ### Additional information
19 |
20 | Additional PR information
21 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Utility.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System;
5 |
6 | namespace Microsoft.Azure.WebJobs.ServiceBus
7 | {
8 | class Utility
9 | {
10 | ///
11 | /// Returns processor count for a worker, for consumption plan always returns 1
12 | ///
13 | ///
14 | public static int GetProcessorCount()
15 | {
16 | string skuValue = Environment.GetEnvironmentVariable(Constants.AzureWebsiteSku);
17 | return string.Equals(skuValue, Constants.DynamicSku, StringComparison.OrdinalIgnoreCase) ? 1 : Environment.ProcessorCount;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/MessageArgumentBindingProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System.Reflection;
5 | using Microsoft.Azure.ServiceBus;
6 | using Microsoft.Azure.WebJobs.Host.Bindings;
7 |
8 |
9 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
10 | {
11 | internal class MessageArgumentBindingProvider : IQueueArgumentBindingProvider
12 | {
13 | public IArgumentBinding TryCreate(ParameterInfo parameter)
14 | {
15 | if (!parameter.IsOut || parameter.ParameterType != typeof(Message).MakeByRefType())
16 | {
17 | return null;
18 | }
19 |
20 | return new MessageArgumentBinding();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/ServiceBusEntity.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 | using Microsoft.Azure.ServiceBus;
8 | using Microsoft.Azure.ServiceBus.Core;
9 |
10 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
11 | {
12 | internal class ServiceBusEntity
13 | {
14 | public MessageSender MessageSender { get; set; }
15 |
16 | public EntityType EntityType { get; set; } = EntityType.Queue;
17 |
18 | public Task SendAndCreateEntityIfNotExistsAsync(Message message, Guid functionInstanceId, CancellationToken cancellationToken)
19 | {
20 | return MessageSender.SendAndCreateEntityIfNotExists(message, functionInstanceId, EntityType, cancellationToken);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/UserTypeToBrokeredMessageConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System.Diagnostics.CodeAnalysis;
5 | using System.IO;
6 | using Microsoft.Azure.WebJobs.Host.Converters;
7 | using Microsoft.Azure.ServiceBus;
8 | using Newtonsoft.Json;
9 |
10 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
11 | {
12 | internal class UserTypeToBrokeredMessageConverter : IConverter
13 | {
14 | public Message Convert(TInput input)
15 | {
16 | string text = JsonConvert.SerializeObject(input, Constants.JsonSerializerSettings);
17 | byte[] bytes = StrictEncodings.Utf8.GetBytes(text);
18 |
19 | return new Message(bytes)
20 | {
21 | ContentType = ContentTypes.ApplicationJson
22 | };
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Triggers/MessageToByteArrayConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.IO;
6 | using System.Runtime.Serialization;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 | using Microsoft.Azure.WebJobs.Host.Converters;
10 | using Microsoft.Azure.ServiceBus;
11 |
12 | namespace Microsoft.Azure.WebJobs.ServiceBus.Triggers
13 | {
14 | internal class MessageToByteArrayConverter : IAsyncConverter
15 | {
16 | public Task ConvertAsync(Message input, CancellationToken cancellationToken)
17 | {
18 | if (input == null)
19 | {
20 | throw new ArgumentNullException(nameof(input));
21 | }
22 |
23 | cancellationToken.ThrowIfCancellationRequested();
24 |
25 | return Task.FromResult(input.Body);
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/ByteArrayToBrokeredMessageConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Diagnostics.CodeAnalysis;
6 | using Microsoft.Azure.ServiceBus;
7 |
8 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
9 | {
10 | internal class ByteArrayToBrokeredMessageConverter : IConverter
11 | {
12 | [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
13 | public Message Convert(byte[] input)
14 | {
15 | if (input == null)
16 | {
17 | throw new InvalidOperationException("A brokered message cannot contain a null byte array instance.");
18 | }
19 |
20 | return new Message(input)
21 | {
22 | ContentType = ContentTypes.ApplicationOctetStream
23 | };
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Config/BatchOptions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 | using System;
4 |
5 | namespace Microsoft.Azure.WebJobs.ServiceBus
6 | {
7 | ///
8 | /// Configuration options for ServiceBus batch receive.
9 | ///
10 | public class BatchOptions
11 | {
12 | ///
13 | /// The maximum number of messages that will be received.
14 | ///
15 | public int MaxMessageCount { get; set; }
16 |
17 | ///
18 | /// The time span the client waits for receiving a message before it times out.
19 | ///
20 | public TimeSpan OperationTimeout { get; set; }
21 |
22 | ///
23 | /// Gets or sets a value that indicates whether the messages should be completed after successful processing.
24 | ///
25 | public bool AutoComplete { get; set; }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Listeners/ServiceBusTriggerMetrics.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using Microsoft.Azure.WebJobs.Host.Scale;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Text;
8 |
9 | namespace Microsoft.Azure.WebJobs.ServiceBus.Listeners
10 | {
11 | internal class ServiceBusTriggerMetrics : ScaleMetrics
12 | {
13 | ///
14 | /// The number of messages currently in the queue/topic.
15 | ///
16 | public long MessageCount { get; set; }
17 |
18 | ///
19 | /// The number of partitions.
20 | ///
21 | public int PartitionCount { get; set; }
22 |
23 | ///
24 | /// The length of time the next message has been
25 | /// sitting there.
26 | ///
27 | public TimeSpan QueueTime { get; set; }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System.Reflection;
5 | using System.Runtime.CompilerServices;
6 |
7 | [assembly: InternalsVisibleTo("Microsoft.Azure.WebJobs.ServiceBus.UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
8 | [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
9 |
--------------------------------------------------------------------------------
/stylecop.json:
--------------------------------------------------------------------------------
1 | {
2 | // ACTION REQUIRED: This file was automatically added to your project, but it
3 | // will not take effect until additional steps are taken to enable it. See the
4 | // following page for additional information:
5 | //
6 | // https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md
7 |
8 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
9 | "settings": {
10 | "documentationRules": {
11 | "companyName": ".NET Foundation",
12 | "copyrightText": "Copyright (c) .NET Foundation. All rights reserved.\r\nLicensed under the MIT License. See License.txt in the project root for license information.",
13 | "xmlHeader": false,
14 | "documentInterfaces": false,
15 | "documentInternalElements": false,
16 | "documentExposedElements": false,
17 | "documentPrivateElements": false,
18 | "documentPrivateFields": false
19 | },
20 | "orderingRules": {
21 | "usingDirectivesPlacement": "outsideNamespace"
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) .NET Foundation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Triggers/OutputConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using Microsoft.Azure.WebJobs.Host.Converters;
5 | using Microsoft.Azure.ServiceBus;
6 |
7 | namespace Microsoft.Azure.WebJobs.ServiceBus.Triggers
8 | {
9 | internal class OutputConverter : IObjectToTypeConverter
10 | where TInput : class
11 | {
12 | private readonly IConverter _innerConverter;
13 |
14 | public OutputConverter(IConverter innerConverter)
15 | {
16 | _innerConverter = innerConverter;
17 | }
18 |
19 | public bool TryConvert(object input, out Message output)
20 | {
21 | TInput typedInput = input as TInput;
22 |
23 | if (typedInput == null)
24 | {
25 | output = null;
26 | return false;
27 | }
28 |
29 | output = _innerConverter.Convert(typedInput);
30 | return true;
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/StringToBrokeredMessageConverter.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Diagnostics.CodeAnalysis;
6 | using System.IO;
7 | using Microsoft.Azure.WebJobs.Host.Converters;
8 | using Microsoft.Azure.ServiceBus;
9 |
10 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
11 | {
12 | internal class StringToBrokeredMessageConverter : IConverter
13 | {
14 | [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
15 | public Message Convert(string input)
16 | {
17 | if (input == null)
18 | {
19 | throw new InvalidOperationException("A brokered message cannot contain a null string instance.");
20 | }
21 |
22 | byte[] bytes = StrictEncodings.Utf8.GetBytes(input);
23 |
24 | return new Message(bytes)
25 | {
26 | ContentType = ContentTypes.TextPlain
27 | };
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/MessageSenderExtensions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Diagnostics;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 | using Microsoft.Azure.WebJobs.ServiceBus.Listeners;
9 | using Microsoft.Azure.ServiceBus;
10 | using Microsoft.Azure.ServiceBus.Core;
11 |
12 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
13 | {
14 | internal static class MessageSenderExtensions
15 | {
16 | public static async Task SendAndCreateEntityIfNotExists(this MessageSender sender, Message message,
17 | Guid functionInstanceId, EntityType entityType, CancellationToken cancellationToken)
18 | {
19 | if (sender == null)
20 | {
21 | throw new ArgumentNullException("sender");
22 | }
23 |
24 | ServiceBusCausalityHelper.EncodePayload(functionInstanceId, message);
25 |
26 | cancellationToken.ThrowIfCancellationRequested();
27 |
28 | await sender.SendAsync(message);
29 | return;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/IBindableServiceBusPath.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System.Collections.Generic;
5 |
6 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
7 | {
8 | internal interface IBindableServiceBusPath
9 | {
10 | string QueueOrTopicNamePattern { get; }
11 |
12 | ///
13 | /// Gets a value indicating whether this path is bound.
14 | ///
15 | bool IsBound { get; }
16 |
17 | ///
18 | /// Gets the collection of parameter names for the path.
19 | ///
20 | IEnumerable ParameterNames { get; }
21 |
22 | ///
23 | /// Bind to the path.
24 | ///
25 | /// The binding data.
26 | /// The path binding.
27 | string Bind(IReadOnlyDictionary bindingData);
28 |
29 | ///
30 | /// Gets a string representation of the path.
31 | ///
32 | ///
33 | string ToString();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/test/Microsoft.Azure.WebJobs.Extensions.ServiceBus.Tests/PublicSurfaceTests.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using Microsoft.Azure.WebJobs.Host.TestCommon;
5 | using Xunit;
6 |
7 | namespace Microsoft.Azure.WebJobs.Host.UnitTests
8 | {
9 | public class PublicSurfaceTests
10 | {
11 | [Fact]
12 | public void WebJobs_Extensions_ServiceBus_VerifyPublicSurfaceArea()
13 | {
14 | var assembly = typeof(ServiceBusAttribute).Assembly;
15 |
16 | var expected = new[]
17 | {
18 | "Constants",
19 | "EntityType",
20 | "MessageProcessor",
21 | "MessagingProvider",
22 | "ServiceBusAccountAttribute",
23 | "ServiceBusAttribute",
24 | "ServiceBusTriggerAttribute",
25 | "ServiceBusHostBuilderExtensions",
26 | "ServiceBusOptions",
27 | "ServiceBusWebJobsStartup",
28 | "SessionMessageProcessor",
29 | "BatchOptions"
30 | };
31 |
32 | TestHelpers.AssertPublicTypes(expected, assembly);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/CompositeArgumentBindingProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System.Collections.Generic;
5 | using System.Reflection;
6 | using Microsoft.Azure.WebJobs.Host.Bindings;
7 |
8 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
9 | {
10 | internal class CompositeArgumentBindingProvider : IQueueArgumentBindingProvider
11 | {
12 | private readonly IEnumerable _providers;
13 |
14 | public CompositeArgumentBindingProvider(params IQueueArgumentBindingProvider[] providers)
15 | {
16 | _providers = providers;
17 | }
18 |
19 | public IArgumentBinding TryCreate(ParameterInfo parameter)
20 | {
21 | foreach (IQueueArgumentBindingProvider provider in _providers)
22 | {
23 | IArgumentBinding binding = provider.TryCreate(parameter);
24 |
25 | if (binding != null)
26 | {
27 | return binding;
28 | }
29 | }
30 |
31 | return null;
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "AzureWebJobs", Scope = "member", Target = "Microsoft.Azure.WebJobs.ServiceBus.MessagingProvider.#GetConnectionString(System.String)")]
5 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Prefetch", Scope = "member", Target = "Microsoft.Azure.WebJobs.ServiceBus.ServiceBusConfiguration.#PrefetchCount")]
6 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Scope = "type", Target = "Microsoft.Azure.WebJobs.ServiceBus.EventHubListener+Listenter")]
7 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Scope = "type", Target = "Microsoft.Azure.WebJobs.ServiceBus.EventHubListener+Listener")]
8 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1014:MarkAssembliesWithClsCompliant")]
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Service Bus Extension for Azure Functions [Archived]
2 |
3 | This GitHub project has been archived. Ongoing development on this project can be found in https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/servicebus/Microsoft.Azure.WebJobs.Extensions.ServiceBus.
4 |
5 | This extension provides functionality for receiving Service Bus messges in Azure Functions, allowing you to easily write functions that respond to any message published to Service Bus.
6 |
7 | |Branch|Status|
8 | |---|---|
9 | |dev|[](https://azfunc.visualstudio.com/Azure%20Functions/_build/latest?definitionId=17&branchName=dev)
10 |
11 | ## License
12 |
13 | This project is under the benevolent umbrella of the [.NET Foundation](http://www.dotnetfoundation.org/) and is licensed under [the MIT License](https://github.com/Azure/azure-webjobs-sdk/blob/master/LICENSE.txt)
14 |
15 | ## Contributing
16 |
17 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
18 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Listeners/ServiceBusEntityPathHelper.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 | using System.Text.RegularExpressions;
8 |
9 | namespace Microsoft.Azure.WebJobs.ServiceBus.Listeners
10 | {
11 | internal static class ServiceBusEntityPathHelper
12 | {
13 | public static EntityType ParseEntityType(string entityPath)
14 | {
15 | return entityPath.IndexOf("/Subscriptions/", StringComparison.OrdinalIgnoreCase) >= 0 ? EntityType.Topic : EntityType.Queue;
16 | }
17 |
18 | public static void ParseTopicAndSubscription(string entityPath, out string topic, out string subscription)
19 | {
20 | string[] arr = Regex.Split(entityPath, "/Subscriptions/", RegexOptions.IgnoreCase);
21 |
22 | if (arr.Length < 2)
23 | {
24 | throw new InvalidOperationException($"{entityPath} is either formatted incorrectly, or is not a valid Service Bus subscription path");
25 | }
26 |
27 | topic = arr[0];
28 | subscription = arr[1];
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Listeners/ServiceBusCausalityHelper.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using Microsoft.Azure.ServiceBus;
6 |
7 | namespace Microsoft.Azure.WebJobs.ServiceBus.Listeners
8 | {
9 | internal static class ServiceBusCausalityHelper
10 | {
11 | private const string ParentGuidFieldName = "$AzureWebJobsParentId";
12 |
13 | public static void EncodePayload(Guid functionOwner, Message msg)
14 | {
15 | msg.UserProperties[ParentGuidFieldName] = functionOwner.ToString();
16 | }
17 |
18 | public static Guid? GetOwner(Message msg)
19 | {
20 | object parent;
21 | if (msg.UserProperties.TryGetValue(ParentGuidFieldName, out parent))
22 | {
23 | var parentString = parent as string;
24 | if (parentString != null)
25 | {
26 | Guid parentGuid;
27 | if (Guid.TryParse(parentString, out parentGuid))
28 | {
29 | return parentGuid;
30 | }
31 | }
32 | }
33 | return null;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Constants.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using Newtonsoft.Json;
5 |
6 | namespace Microsoft.Azure.WebJobs.ServiceBus
7 | {
8 | public static class Constants
9 | {
10 | private static JsonSerializerSettings _serializerSettings = new JsonSerializerSettings
11 | {
12 | // The default value, DateParseHandling.DateTime, drops time zone information from DateTimeOffets.
13 | // This value appears to work well with both DateTimes (without time zone information) and DateTimeOffsets.
14 | DateParseHandling = DateParseHandling.DateTimeOffset,
15 | NullValueHandling = NullValueHandling.Ignore,
16 | Formatting = Formatting.Indented
17 | };
18 |
19 | public static JsonSerializerSettings JsonSerializerSettings
20 | {
21 | get
22 | {
23 | return _serializerSettings;
24 | }
25 | }
26 |
27 | public const string DefaultConnectionStringName = "ServiceBus";
28 | public const string DefaultConnectionSettingStringName = "AzureWebJobsServiceBus";
29 | public const string DynamicSku = "Dynamic";
30 | public const string AzureWebsiteSku = "WEBSITE_SKU";
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/BoundServiceBusPath.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System.Collections.Generic;
5 | using System.Linq;
6 |
7 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
8 | {
9 | ///
10 | /// Bindable queue or topic path strategy implementation for "degenerate" bindable patterns,
11 | /// i.e. containing no parameters.
12 | ///
13 | internal class BoundServiceBusPath : IBindableServiceBusPath
14 | {
15 | private readonly string _queueOrTopicNamePattern;
16 |
17 | public BoundServiceBusPath(string queueOrTopicNamePattern)
18 | {
19 | _queueOrTopicNamePattern = queueOrTopicNamePattern;
20 | }
21 |
22 | public string QueueOrTopicNamePattern
23 | {
24 | get { return _queueOrTopicNamePattern; }
25 | }
26 |
27 | public bool IsBound
28 | {
29 | get { return true; }
30 | }
31 |
32 | public IEnumerable ParameterNames
33 | {
34 | get { return Enumerable.Empty(); }
35 | }
36 |
37 | public string Bind(IReadOnlyDictionary bindingData)
38 | {
39 | return QueueOrTopicNamePattern;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Microsoft.Azure.WebJobs.Extensions.ServiceBus/Bindings/CollectorValueProvider.cs:
--------------------------------------------------------------------------------
1 | // Copyright (c) .NET Foundation. All rights reserved.
2 | // Licensed under the MIT License. See License.txt in the project root for license information.
3 |
4 | using System;
5 | using System.Threading.Tasks;
6 | using Microsoft.Azure.WebJobs.Host.Bindings;
7 |
8 | namespace Microsoft.Azure.WebJobs.ServiceBus.Bindings
9 | {
10 | internal class CollectorValueProvider : IValueProvider
11 | {
12 | private readonly ServiceBusEntity _entity;
13 | private readonly object _value;
14 | private readonly Type _valueType;
15 |
16 | public CollectorValueProvider(ServiceBusEntity entity, object value, Type valueType)
17 | {
18 | if (value != null && !valueType.IsAssignableFrom(value.GetType()))
19 | {
20 | throw new InvalidOperationException("value is not of the correct type.");
21 | }
22 |
23 | _entity = entity;
24 | _value = value;
25 | _valueType = valueType;
26 | }
27 |
28 | public Type Type
29 | {
30 | get { return _valueType; }
31 | }
32 |
33 | public Task