Skip to content

Commit

Permalink
Ported original sample to the latest version of MT
Browse files Browse the repository at this point in the history
  • Loading branch information
phatboyg committed Dec 31, 2020
0 parents commit e37db72
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .gitignore
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
39 changes: 39 additions & 0 deletions Sample.AzureFunction.sln
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
27 changes: 27 additions & 0 deletions src/Sample.AzureFunction/AuditOrderFunctions.cs
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);
}
}
}
15 changes: 15 additions & 0 deletions src/Sample.AzureFunction/Consumers/AuditOrderConsumer.cs
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);
}
}
}
7 changes: 7 additions & 0 deletions src/Sample.AzureFunction/Consumers/ConsumerNamespace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Sample.AzureFunction.Consumers
{
public struct ConsumerNamespace
{

}
}
24 changes: 24 additions & 0 deletions src/Sample.AzureFunction/Consumers/SubmitOrderConsumer.cs
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});
}
}
}
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));
}
}
}
10 changes: 10 additions & 0 deletions src/Sample.AzureFunction/OrderAccepted.cs
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; }
}
}
12 changes: 12 additions & 0 deletions src/Sample.AzureFunction/OrderReceived.cs
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; }
}
}
23 changes: 23 additions & 0 deletions src/Sample.AzureFunction/Sample.AzureFunction.csproj
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>
24 changes: 24 additions & 0 deletions src/Sample.AzureFunction/Startup.cs
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();
}
}
}
10 changes: 10 additions & 0 deletions src/Sample.AzureFunction/SubmitOrder.cs
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; }
}
}
27 changes: 27 additions & 0 deletions src/Sample.AzureFunction/SubmitOrderFunctions.cs
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);
}
}
}
29 changes: 29 additions & 0 deletions src/Sample.AzureFunction/host.json
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
}
}
}
12 changes: 12 additions & 0 deletions src/Sample.AzureFunction/local.settings.json
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="
}
}

0 comments on commit e37db72

Please sign in to comment.