Skip to content

Commit d4d2595

Browse files
committed
Updated documentation and small tweaks
1 parent 19e490a commit d4d2595

File tree

21 files changed

+561
-83
lines changed

21 files changed

+561
-83
lines changed

Modules/Intent.Modules.AzureFunctions.AzureQueueStorage/Intent.AzureFunctions.AzureQueueStorage.imodspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<id>Intent.AzureFunctions.AzureQueueStorage</id>
44
<version>1.0.0-beta.1</version>
5-
<supportedClientVersions>[4.5.0-a,5.0.0)</supportedClientVersions>
5+
<supportedClientVersions>[4.4.0-a,5.0.0)</supportedClientVersions>
66
<summary>Use Azure Functions to receive and dispatch Azure Queue Storage Messages to an event handler.</summary>
77
<description>Use Azure Functions to receive and dispatch Azure Queue Storage Messages to an event handler.</description>
88
<authors>Intent Architect</authors>
@@ -21,17 +21,17 @@
2121
<factoryExtensions></factoryExtensions>
2222
<moduleSettings></moduleSettings>
2323
<dependencies>
24-
<dependency id="Intent.AzureFunctions" version="5.0.3" />
24+
<dependency id="Intent.AzureFunctions" version="5.0.3" />
2525
<dependency id="Intent.Common" version="3.7.2" />
2626
<dependency id="Intent.Common.CSharp" version="3.8.0" />
2727
<dependency id="Intent.Common.Types" version="3.4.0" />
2828
<dependency id="Intent.Eventing.AzureQueueStorage" version="1.0.0-beta.1" />
29+
<dependency id="Intent.Eventing.Contracts" version="6.0.0" />
2930
<dependency id="Intent.Modelers.Domain" version="3.11.1" />
3031
<dependency id="Intent.Modelers.Eventing" version="6.0.2" />
3132
<dependency id="Intent.Modelers.Services" version="4.0.5" />
3233
<dependency id="Intent.Modelers.Services.EventInteractions" version="2.0.4" />
3334
<dependency id="Intent.OutputManager.RoslynWeaver" version="4.5.1" />
34-
<dependency id="Intent.Eventing.Contracts" version="6.0.0" />
3535
</dependencies>
3636
<files>
3737
<file src="$outDir$/$id$.dll" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<class id="6dab89e6-e67f-41e4-9625-442077fd411d" type="NuGet Package" typeId="f747cc37-29ee-488a-8dbe-755e856a842d">
3+
<name>Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues</name>
4+
<display>Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues</display>
5+
<isAbstract>false</isAbstract>
6+
<sort-children>by-type-then-by-name</sort-children>
7+
<genericTypes />
8+
<isMapped>false</isMapped>
9+
<parentFolderId>e0383871-d928-4234-ad42-c50cd97dd03c</parentFolderId>
10+
<packageId>02ce5521-0b0c-4796-918d-4638bdcc8062</packageId>
11+
<packageName>Intent.AzureFunctions.AzureQueueStorage</packageName>
12+
<stereotypes>
13+
<stereotype stereotypeDefinitionId="265221a5-779c-46c9-a367-8b07b435803b" name="Package Settings">
14+
<addedByDefault>true</addedByDefault>
15+
<definitionPackageName>Intent.ModuleBuilder.CSharp</definitionPackageName>
16+
<definitionPackageId>f2bfb0f7-d304-466f-b923-021d4016b48d</definitionPackageId>
17+
<properties>
18+
<property name="4de9cc21-d4fb-4d52-8dfd-2eb6cf267a9a" display="Friendly Name" isActive="true" />
19+
<property name="67c7c4d8-40ed-48f9-a83c-985eedb32141" display="Locked" value="false" isActive="true" />
20+
<property name="c166c7cf-45e3-484b-9ec5-f7300951f897" display="Private Assets" isActive="true" />
21+
<property name="6bd6430c-8011-435e-bb73-6013477a875d" display="Include Assets" isActive="true" />
22+
</properties>
23+
</stereotype>
24+
</stereotypes>
25+
<metadata />
26+
<childElements>
27+
<childElement id="ecb65a4c-94be-436a-9c9a-e0e90e9dd8ce" type="Package Version" typeId="231f8cf8-517b-4801-9682-991d22f4e662">
28+
<name>5.5.3</name>
29+
<display>5.5.3 ( &gt;= .NETStandard,Version=v2.0 )</display>
30+
<isAbstract>false</isAbstract>
31+
<sort-children>by-type-then-by-name</sort-children>
32+
<genericTypes />
33+
<isMapped>false</isMapped>
34+
<parentFolderId>6dab89e6-e67f-41e4-9625-442077fd411d</parentFolderId>
35+
<packageId>02ce5521-0b0c-4796-918d-4638bdcc8062</packageId>
36+
<packageName>Intent.AzureFunctions.AzureQueueStorage</packageName>
37+
<stereotypes>
38+
<stereotype stereotypeDefinitionId="7af88c37-ce54-49fc-b577-bde869c23462" name="Package Version Settings">
39+
<addedByDefault>true</addedByDefault>
40+
<definitionPackageName>Intent.ModuleBuilder.CSharp</definitionPackageName>
41+
<definitionPackageId>f2bfb0f7-d304-466f-b923-021d4016b48d</definitionPackageId>
42+
<properties>
43+
<property name="b01cea92-0ca1-4dbe-acab-d0f52b39e003" display="Minimum Target Framework" value=".NETStandard,Version=v2.0" isActive="true" />
44+
<property name="d00692b1-6d17-4f1e-9386-a1d0d3ab7b57" display="Locked" value="false" isActive="true" />
45+
</properties>
46+
</stereotype>
47+
</stereotypes>
48+
<metadata />
49+
<childElements>
50+
<childElement id="e4ceb00a-7e25-4c5b-b801-c62900515d77" type="NuGet Dependency" typeId="3097322a-a058-4058-beed-4fcd6272f61d">
51+
<name>Azure.Storage.Queues</name>
52+
<display>Azure.Storage.Queues (12.21.0)</display>
53+
<isAbstract>false</isAbstract>
54+
<value>12.21.0</value>
55+
<genericTypes />
56+
<isMapped>false</isMapped>
57+
<parentFolderId>ecb65a4c-94be-436a-9c9a-e0e90e9dd8ce</parentFolderId>
58+
<packageId>02ce5521-0b0c-4796-918d-4638bdcc8062</packageId>
59+
<packageName>Intent.AzureFunctions.AzureQueueStorage</packageName>
60+
<stereotypes />
61+
<metadata />
62+
<childElements />
63+
</childElement>
64+
<childElement id="c44f8d9b-6237-48d0-8678-26d163a1f348" type="NuGet Dependency" typeId="3097322a-a058-4058-beed-4fcd6272f61d">
65+
<name>Microsoft.Azure.Functions.Worker.Core</name>
66+
<display>Microsoft.Azure.Functions.Worker.Core (1.20.0)</display>
67+
<isAbstract>false</isAbstract>
68+
<value>1.20.0</value>
69+
<genericTypes />
70+
<isMapped>false</isMapped>
71+
<parentFolderId>ecb65a4c-94be-436a-9c9a-e0e90e9dd8ce</parentFolderId>
72+
<packageId>02ce5521-0b0c-4796-918d-4638bdcc8062</packageId>
73+
<packageName>Intent.AzureFunctions.AzureQueueStorage</packageName>
74+
<stereotypes />
75+
<metadata />
76+
<childElements />
77+
</childElement>
78+
<childElement id="3f33b1a5-d0a3-46b9-826d-e0f5c4d5abf7" type="NuGet Dependency" typeId="3097322a-a058-4058-beed-4fcd6272f61d">
79+
<name>Microsoft.Azure.Functions.Worker.Extensions.Abstractions</name>
80+
<display>Microsoft.Azure.Functions.Worker.Extensions.Abstractions (1.3.0)</display>
81+
<isAbstract>false</isAbstract>
82+
<value>1.3.0</value>
83+
<genericTypes />
84+
<isMapped>false</isMapped>
85+
<parentFolderId>ecb65a4c-94be-436a-9c9a-e0e90e9dd8ce</parentFolderId>
86+
<packageId>02ce5521-0b0c-4796-918d-4638bdcc8062</packageId>
87+
<packageName>Intent.AzureFunctions.AzureQueueStorage</packageName>
88+
<stereotypes />
89+
<metadata />
90+
<childElements />
91+
</childElement>
92+
</childElements>
93+
</childElement>
94+
</childElements>
95+
</class>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<class id="e0383871-d928-4234-ad42-c50cd97dd03c" type="NuGet Packages" typeId="4c75c84d-c745-4f0f-b1f4-82eeca01dfc7">
3+
<name>NuGet Packages</name>
4+
<display>NuGet Packages</display>
5+
<isAbstract>false</isAbstract>
6+
<sort-children>by-type-then-by-name</sort-children>
7+
<genericTypes />
8+
<isMapped>false</isMapped>
9+
<parentFolderId>02ce5521-0b0c-4796-918d-4638bdcc8062</parentFolderId>
10+
<packageId>02ce5521-0b0c-4796-918d-4638bdcc8062</packageId>
11+
<packageName>Intent.AzureFunctions.AzureQueueStorage</packageName>
12+
<stereotypes />
13+
<metadata />
14+
<childElements />
15+
</class>

Modules/Intent.Modules.AzureFunctions.AzureQueueStorage/Intent.Modules.AzureFunctions.AzureQueueStorage.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66

77
<ItemGroup>
88
<PackageReference Include="Intent.Modules.Common" Version="3.9.0" />
9-
<PackageReference Include="Intent.Modules.Common.CSharp" Version="3.8.1" />
9+
<PackageReference Include="Intent.Modules.Common.CSharp" Version="3.8.3" />
1010
<PackageReference Include="Intent.Modules.Modelers.Services" Version="4.0.5" />
1111
<PackageReference Include="Intent.Modules.Modelers.Services.EventInteractions" Version="2.0.4" />
1212
<PackageReference Include="Intent.Packager" Version="3.6.0">
1313
<PrivateAssets>all</PrivateAssets>
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
</PackageReference>
1616
<PackageReference Include="Intent.RoslynWeaver.Attributes" Version="3.0.0" />
17-
<PackageReference Include="Intent.SoftwareFactory.SDK" Version="3.10.0-pre.2" />
17+
<PackageReference Include="Intent.SoftwareFactory.SDK" Version="3.10.0-pre.2" />
1818
</ItemGroup>
1919

2020
<ItemGroup>
2121
<ProjectReference Include="..\Intent.Modules.AzureFunctions\Intent.Modules.AzureFunctions.csproj" />
22+
<ProjectReference Include="..\Intent.Modules.Eventing.AzureQueueStorage\Intent.Modules.Eventing.AzureQueueStorage.csproj" />
2223
</ItemGroup>
2324

2425
</Project>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using Intent.Engine;
3+
using Intent.Modules.Common.CSharp.Nuget;
4+
using Intent.Modules.Common.VisualStudio;
5+
using Intent.RoslynWeaver.Attributes;
6+
7+
[assembly: DefaultIntentManaged(Mode.Fully)]
8+
[assembly: IntentTemplate("Intent.ModuleBuilder.CSharp.Templates.NugetPackages", Version = "1.0")]
9+
10+
namespace Intent.Modules.AzureFunctions.AzureQueueStorage
11+
{
12+
public class NugetPackages : INugetPackages
13+
{
14+
public const string MicrosoftAzureFunctionsWorkerExtensionsStorageQueuesPackageName = "Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues";
15+
16+
public void RegisterPackages()
17+
{
18+
NugetRegistry.Register(MicrosoftAzureFunctionsWorkerExtensionsStorageQueuesPackageName,
19+
(framework) => (framework.Major, framework.Minor) switch
20+
{
21+
( >= 2, >= 0) => new PackageVersion("5.5.3")
22+
.WithNugetDependency("Azure.Storage.Queues", "12.21.0")
23+
.WithNugetDependency("Microsoft.Azure.Functions.Worker.Core", "1.20.0")
24+
.WithNugetDependency("Microsoft.Azure.Functions.Worker.Extensions.Abstractions", "1.3.0"),
25+
_ => throw new Exception($"Unsupported Framework `{framework.Major}` for NuGet package '{MicrosoftAzureFunctionsWorkerExtensionsStorageQueuesPackageName}'"),
26+
}
27+
);
28+
}
29+
30+
public static NugetPackageInfo MicrosoftAzureFunctionsWorkerExtensionsStorageQueues(IOutputTarget outputTarget) => NugetRegistry.GetVersion(MicrosoftAzureFunctionsWorkerExtensionsStorageQueuesPackageName, outputTarget.GetMaxNetAppVersion());
31+
}
32+
}

Modules/Intent.Modules.AzureFunctions.AzureQueueStorage/Templates/AzureFunctionConsumer/AzureFunctionConsumerTemplatePartial.cs

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
using Intent.Engine;
2+
using Intent.Modelers.Eventing.Api;
3+
using Intent.Modelers.Services.Api;
24
using Intent.Modelers.Services.EventInteractions;
35
using Intent.Modules.AzureFunctions.Settings;
46
using Intent.Modules.Common;
57
using Intent.Modules.Common.CSharp.Api;
68
using Intent.Modules.Common.CSharp.Builder;
9+
using Intent.Modules.Common.CSharp.Configuration;
10+
using Intent.Modules.Common.CSharp.DependencyInjection;
711
using Intent.Modules.Common.CSharp.Templates;
812
using Intent.Modules.Common.Templates;
913
using Intent.Modules.Common.Types.Api;
14+
using Intent.Modules.Common.UnitOfWork.Shared;
15+
using Intent.Modules.Eventing.AzureQueueStorage;
16+
using Intent.Modules.Eventing.AzureQueueStorage.Settings;
17+
using Intent.Modules.Eventing.AzureQueueStorage.Templates;
18+
using Intent.Modules.Eventing.Contracts.Templates;
1019
using Intent.RoslynWeaver.Attributes;
1120
using Intent.Templates;
1221
using System;
1322
using System.Collections.Generic;
1423
using System.Linq;
24+
using static System.Net.Mime.MediaTypeNames;
1525

1626
[assembly: DefaultIntentManaged(Mode.Fully)]
1727
[assembly: IntentTemplate("Intent.ModuleBuilder.CSharp.Templates.CSharpTemplatePartial", Version = "1.0")]
@@ -26,19 +36,86 @@ public partial class AzureFunctionConsumerTemplate : CSharpTemplateBase<Integrat
2636
[IntentManaged(Mode.Fully, Body = Mode.Ignore)]
2737
public AzureFunctionConsumerTemplate(IOutputTarget outputTarget, IntegrationEventHandlerModel model) : base(TemplateId, outputTarget, model)
2838
{
39+
AddNugetDependency(NugetPackages.MicrosoftAzureFunctionsWorkerExtensionsStorageQueues(outputTarget));
40+
2941
CSharpFile = new CSharpFile(this.GetNamespace(), this.GetRelativeLocation())
3042
.AddClass(GetFunctionName(), @class =>
3143
{
44+
@class.AddField(UseType("System.Text.Json.JsonSerializerOptions"), "_serializerOptions", @field =>
45+
{
46+
@field.PrivateReadOnly();
47+
});
48+
3249
@class.AddConstructor(ctor =>
3350
{
34-
ctor.AddParameter("string", "exampleParam", param =>
51+
ctor.AddParameter(this.GetAzureQueueStorageEventDispatcherInterfaceName(), "dispatcher", param => param.IntroduceReadonlyField());
52+
ctor.AddParameter(UseType($"Microsoft.Extensions.Logging.ILogger<{@class.Name}>"), "logger", param => param.IntroduceReadonlyField());
53+
ctor.AddParameter(this.GetEventBusInterfaceName(), "eventBus", param => param.IntroduceReadonlyField());
54+
ctor.AddParameter(UseType("System.IServiceProvider"), "serviceProvider", param => param.IntroduceReadonlyField());
55+
56+
ctor.AddObjectInitStatement("_serializerOptions", new CSharpObjectInitializerBlock("new JsonSerializerOptions")
57+
.AddAssignmentStatement("PropertyNamingPolicy", new CSharpStatement("JsonNamingPolicy.CamelCase"))
58+
.AddAssignmentStatement("PropertyNameCaseInsensitive", new CSharpStatement("true")).WithSemicolon());
59+
});
60+
61+
@class.AddMethod(UseType("System.Threading.Tasks.Task"), "Run", method =>
62+
{
63+
method.Async();
64+
method.AddAttribute("Function", attr => attr.AddArgument($@"""{@class.Name}"""));
65+
method.AddParameter(this.GetAzureQueueStorageEnvelopeName(), "message", param =>
66+
{
67+
param.AddAttribute(UseType("Microsoft.Azure.Functions.Worker.QueueTrigger"), attr =>
68+
{
69+
var messages = Model.IntegrationEventSubscriptions().Select(s => s.Element.AsMessageModel());
70+
var commandModels = Model.IntegrationCommandSubscriptions().Select(s => s.Element.AsIntegrationCommandModel());
71+
72+
var queueName = messages is not null && messages.Any() ? HelperExtensions.GetMessageQueue(messages.First()) :
73+
commandModels is not null && commandModels.Any() ? HelperExtensions.GetIntegrationCommandQueue(commandModels.First()) :
74+
throw new InvalidOperationException($"Subscription could not be found for IntegrationEventHandler ['{Model.Id}', '{Model.Name}']");
75+
76+
attr.AddArgument($@"""{queueName}""");
77+
attr.AddArgument(@"Connection = ""QueueStorage:DefaultEndpoint""");
78+
});
79+
});
80+
method.AddParameter(UseType("System.Threading.CancellationToken"), "cancellationToken");
81+
82+
method.AddTryBlock(block =>
83+
{
84+
var dispatch = new CSharpAwaitExpression(new CSharpInvocationStatement("_dispatcher", "DispatchAsync")
85+
.AddArgument("_serviceProvider")
86+
.AddArgument("message")
87+
.AddArgument("_serializerOptions")
88+
.AddArgument("cancellationToken"));
89+
dispatch.AddMetadata("service-dispatch-statement", true);
90+
91+
block.ApplyUnitOfWorkImplementations(this, @class.Constructors.First(), dispatch);
92+
93+
block.AddStatement($@"await _eventBus.FlushAllAsync(cancellationToken);");
94+
});
95+
method.AddCatchBlock(UseType("System.Exception"), "ex", block =>
3596
{
36-
param.IntroduceReadonlyField();
97+
block.AddStatement($@"_logger.LogError(ex, ""Error processing {@class.Name}"");");
98+
block.AddStatement("throw;");
3799
});
38100
});
39101
});
40102
}
41103

104+
public override void AfterTemplateRegistration()
105+
{
106+
if (ExecutionContext.Settings.GetAzureQueueStorageSettings().MessageEncoding().AsEnum() == AzureQueueStorageSettings.MessageEncodingOptionsEnum.None)
107+
{
108+
ExecutionContext.EventDispatcher.Publish(new HostSettingRegistrationRequest("extensions", new
109+
{
110+
queues = new
111+
{
112+
messageEncoding = "none"
113+
}
114+
}));
115+
}
116+
}
117+
//
118+
42119
private string GetFunctionName()
43120
{
44121
var functionName = $"{Model.Name.RemoveSuffix("Handler")}Consumer";

0 commit comments

Comments
 (0)