-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ported original sample to the latest version of MT
- Loading branch information
0 parents
commit e37db72
Showing
15 changed files
with
341 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
build_output/* | ||
build_artifacts/* | ||
build_temp/* | ||
*.suo | ||
*.user | ||
packages | ||
*.dotCover | ||
|
||
*.ncrunch* | ||
.vs | ||
|
||
.fake | ||
|
||
src/logs/* | ||
|
||
**/*.sln* | ||
bin | ||
obj | ||
_ReSharper* | ||
|
||
*.csproj.user | ||
*.resharper.user | ||
*.resharper | ||
*.ReSharper | ||
*.cache | ||
*~ | ||
*.swp | ||
*.bak | ||
*.orig | ||
|
||
NuGet.exe | ||
packages | ||
|
||
# Tests | ||
TestResult.xml | ||
submit.xml | ||
SolutionVersion.cs | ||
src/SolutionVersion.cs | ||
doc/build/* | ||
*.[lm]df | ||
*.runsettings | ||
|
||
# osx noise | ||
.DS_Store | ||
*.DotSettings | ||
/src/MassTransit.SimpleInjectorIntegration/MassTransit.SimpleInjectorIntegration.csproj.nuspec | ||
*.DS_Store | ||
|
||
docs/.vuepress/dist | ||
_book | ||
/node_modules | ||
.vscode | ||
**/.idea/ | ||
appsettings.Development.json | ||
package-lock.json | ||
|
||
|
||
# Cake | ||
tools/** | ||
!tools/packages.config | ||
|
||
# Artifacts | ||
artifacts/** | ||
artifacts_old/** | ||
/src/.ionide |
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,39 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{1BB9C989-DB6F-45B3-BC9D-BB0A3193BBBF}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.AzureFunction", "src\Sample.AzureFunction\Sample.AzureFunction.csproj", "{1EA6F509-7534-45FB-B725-B1421DAB30A4}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Debug|x64.Build.0 = Debug|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Debug|x86.Build.0 = Debug|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Release|x64.ActiveCfg = Release|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Release|x64.Build.0 = Release|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Release|x86.ActiveCfg = Release|Any CPU | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{1EA6F509-7534-45FB-B725-B1421DAB30A4} = {1BB9C989-DB6F-45B3-BC9D-BB0A3193BBBF} | ||
EndGlobalSection | ||
EndGlobal |
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,27 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MassTransit.WebJobs.EventHubsIntegration; | ||
using Microsoft.Azure.EventHubs; | ||
using Microsoft.Azure.WebJobs; | ||
using Sample.AzureFunction.Consumers; | ||
|
||
namespace Sample.AzureFunction | ||
{ | ||
public class AuditOrderFunctions | ||
{ | ||
const string AuditOrderEventHubName = "audit-order"; | ||
readonly IEventReceiver _receiver; | ||
|
||
public AuditOrderFunctions(IEventReceiver receiver) | ||
{ | ||
_receiver = receiver; | ||
} | ||
|
||
[FunctionName("AuditOrder")] | ||
public Task AuditOrderAsync([EventHubTrigger(AuditOrderEventHubName, Connection = "AzureWebJobsEventHub")] | ||
EventData message, CancellationToken cancellationToken) | ||
{ | ||
return _receiver.HandleConsumer<AuditOrderConsumer>(AuditOrderEventHubName, message, cancellationToken); | ||
} | ||
} | ||
} |
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,15 @@ | ||
using System.Threading.Tasks; | ||
using MassTransit; | ||
using MassTransit.Context; | ||
|
||
namespace Sample.AzureFunction.Consumers | ||
{ | ||
public class AuditOrderConsumer : | ||
IConsumer<OrderReceived> | ||
{ | ||
public async Task Consume(ConsumeContext<OrderReceived> context) | ||
{ | ||
LogContext.Debug?.Log("Received Order: {OrderNumber}", context.Message.OrderNumber); | ||
} | ||
} | ||
} |
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 @@ | ||
namespace Sample.AzureFunction.Consumers | ||
{ | ||
public struct ConsumerNamespace | ||
{ | ||
|
||
} | ||
} |
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,24 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using MassTransit; | ||
using MassTransit.Context; | ||
|
||
namespace Sample.AzureFunction.Consumers | ||
{ | ||
public class SubmitOrderConsumer : | ||
IConsumer<SubmitOrder> | ||
{ | ||
public Task Consume(ConsumeContext<SubmitOrder> context) | ||
{ | ||
LogContext.Debug?.Log("Processing Order: {OrderNumber}", context.Message.OrderNumber); | ||
|
||
context.Publish<OrderReceived>(new | ||
{ | ||
context.Message.OrderNumber, | ||
Timestamp = DateTime.UtcNow | ||
}); | ||
|
||
return context.RespondAsync<OrderAccepted>(new {context.Message.OrderNumber}); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/Sample.AzureFunction/Consumers/SubmitOrderConsumerDefinition.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,17 @@ | ||
using GreenPipes; | ||
using MassTransit; | ||
using MassTransit.ConsumeConfigurators; | ||
using MassTransit.Definition; | ||
|
||
namespace Sample.AzureFunction.Consumers | ||
{ | ||
public class SubmitOrderConsumerDefinition : | ||
ConsumerDefinition<SubmitOrderConsumer> | ||
{ | ||
protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointConfigurator, | ||
IConsumerConfigurator<SubmitOrderConsumer> consumerConfigurator) | ||
{ | ||
endpointConfigurator.UseMessageRetry(x => x.Intervals(10, 100, 500, 1000)); | ||
} | ||
} | ||
} |
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,10 @@ | ||
using System; | ||
|
||
namespace Sample.AzureFunction | ||
{ | ||
public interface OrderAccepted | ||
{ | ||
Guid OrderId { get; } | ||
string OrderNumber { get; } | ||
} | ||
} |
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,12 @@ | ||
using System; | ||
|
||
namespace Sample.AzureFunction | ||
{ | ||
public interface OrderReceived | ||
{ | ||
Guid OrderId { get; } | ||
DateTime Timestamp { get; } | ||
|
||
string OrderNumber { get; } | ||
} | ||
} |
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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<AzureFunctionsVersion>v3</AzureFunctionsVersion> | ||
<NoWarn>CS0618,CS1998,CS1591</NoWarn> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="MassTransit.WebJobs.EventHubs" Version="7.1.1" /> | ||
<PackageReference Include="MassTransit.WebJobs.ServiceBus" Version="7.1.1" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.0.0" /> | ||
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.2.0" /> | ||
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.6" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="host.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="local.settings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<CopyToPublishDirectory>Never</CopyToPublishDirectory> | ||
</None> | ||
</ItemGroup> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using MassTransit; | ||
using Microsoft.Azure.Functions.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Sample.AzureFunction; | ||
using Sample.AzureFunction.Consumers; | ||
|
||
[assembly: FunctionsStartup(typeof(Startup))] | ||
|
||
|
||
namespace Sample.AzureFunction | ||
{ | ||
public class Startup : | ||
FunctionsStartup | ||
{ | ||
public override void Configure(IFunctionsHostBuilder builder) | ||
{ | ||
builder.Services | ||
.AddScoped<SubmitOrderFunctions>() | ||
.AddScoped<AuditOrderFunctions>() | ||
.AddMassTransitForAzureFunctions(cfg => { cfg.AddConsumersFromNamespaceContaining<ConsumerNamespace>(); }) | ||
.AddMassTransitEventHub(); | ||
} | ||
} | ||
} |
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,10 @@ | ||
using System; | ||
|
||
namespace Sample.AzureFunction | ||
{ | ||
public interface SubmitOrder | ||
{ | ||
Guid OrderId { get; } | ||
string OrderNumber { get; } | ||
} | ||
} |
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,27 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MassTransit.WebJobs.ServiceBusIntegration; | ||
using Microsoft.Azure.ServiceBus; | ||
using Microsoft.Azure.WebJobs; | ||
using Sample.AzureFunction.Consumers; | ||
|
||
namespace Sample.AzureFunction | ||
{ | ||
public class SubmitOrderFunctions | ||
{ | ||
const string SubmitOrderQueueName = "submit-order"; | ||
readonly IMessageReceiver _receiver; | ||
|
||
public SubmitOrderFunctions(IMessageReceiver receiver) | ||
{ | ||
_receiver = receiver; | ||
} | ||
|
||
[FunctionName("SubmitOrder")] | ||
public Task SubmitOrderAsync([ServiceBusTrigger(SubmitOrderQueueName)] | ||
Message message, CancellationToken cancellationToken) | ||
{ | ||
return _receiver.HandleConsumer<SubmitOrderConsumer>(SubmitOrderQueueName, message, cancellationToken); | ||
} | ||
} | ||
} |
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,29 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingSettings": { | ||
"isEnabled": true | ||
} | ||
}, | ||
"logLevel": { | ||
"MassTransit": "Debug", | ||
"Sample.AzureFunctions.ServiceBus": "Information" | ||
} | ||
}, | ||
"extensions": { | ||
"serviceBus": { | ||
"prefetchCount": 32, | ||
"messageHandlerOptions": { | ||
"autoComplete": true, | ||
"maxConcurrentCalls": 32, | ||
"maxAutoRenewDuration": "00:30:00" | ||
} | ||
}, | ||
"eventHub": { | ||
"maxBatchSize": 64, | ||
"prefetchCount": 256, | ||
"batchCheckpointFrequency": 1 | ||
} | ||
} | ||
} |
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,12 @@ | ||
{ | ||
"IsEncrypted": false, | ||
"Values": { | ||
"FUNCTIONS_WORKER_RUNTIME": "dotnet", | ||
"AzureWebJobsStorage": "", | ||
"AzureWebJobsServiceBus": "", | ||
"AzureWebJobsEventHub": "", | ||
"FUNCTIONS_EXTENSION_VERSION": "~3", | ||
"APPINSIGHTS_INSTRUMENTATIONKEY": "", | ||
"APPLICATIONINSIGHTS_CONNECTION_STRING": "InstrumentationKey=" | ||
} | ||
} |