-
Notifications
You must be signed in to change notification settings - Fork 15
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 #111 from awslabs/dev
Merge dev to main for next beta release
- Loading branch information
Showing
43 changed files
with
1,364 additions
and
88 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
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 |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
], | ||
"exclude": [ | ||
"_site/**", | ||
"docs/**", | ||
"filter.yml" | ||
] | ||
} | ||
|
29 changes: 29 additions & 0 deletions
29
sampleapps/PollyIntegration/MessageHandlers/ChatMessageHandler.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,29 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using AWS.Messaging; | ||
using PollyIntegration.Models; | ||
|
||
namespace PollyIntegration.MessageHandlers; | ||
|
||
public class ChatMessageHandler : IMessageHandler<ChatMessage> | ||
{ | ||
public Task<MessageProcessStatus> HandleAsync(MessageEnvelope<ChatMessage> messageEnvelope, CancellationToken token = default) | ||
{ | ||
if (messageEnvelope == null) | ||
{ | ||
return Task.FromResult(MessageProcessStatus.Failed()); | ||
} | ||
|
||
if (messageEnvelope.Message == null) | ||
{ | ||
return Task.FromResult(MessageProcessStatus.Failed()); | ||
} | ||
|
||
var message = messageEnvelope.Message; | ||
|
||
Console.WriteLine($"Message Description: {message.MessageDescription}"); | ||
|
||
return Task.FromResult(MessageProcessStatus.Success()); | ||
} | ||
} |
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,9 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
namespace PollyIntegration.Models; | ||
|
||
public class ChatMessage | ||
{ | ||
public string MessageDescription { get; set; } = string.Empty; | ||
} |
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,28 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\r | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using AWS.Messaging.Configuration; | ||
using AWS.Messaging.Services.Backoff; | ||
using Polly; | ||
using Polly.Registry; | ||
|
||
namespace PollyIntegration; | ||
|
||
public class PollyBackoffHandler : IBackoffHandler | ||
{ | ||
private readonly ResiliencePipelineProvider<string> _resiliencePipelineProvider; | ||
|
||
public PollyBackoffHandler(ResiliencePipelineProvider<string> resiliencePipelineProvider) | ||
{ | ||
_resiliencePipelineProvider = resiliencePipelineProvider; | ||
} | ||
|
||
public async Task<T> BackoffAsync<T>(Func<Task<T>> task, SQSMessagePollerConfiguration configuration, CancellationToken token) | ||
{ | ||
ResiliencePipeline pipeline = _resiliencePipelineProvider.GetPipeline("my-pipeline"); | ||
|
||
// Execute the pipeline | ||
return await pipeline.ExecuteAsync(async cancellationToken => await task.Invoke(), | ||
token); | ||
} | ||
} |
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,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Remove="appsettings.json" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Content Include="appsettings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.*" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" /> | ||
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.6.0" /> | ||
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" /> | ||
<PackageReference Include="Polly.Core" Version="8.1.0" /> | ||
<PackageReference Include="Polly.Extensions" Version="8.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\AWS.Messaging.Telemetry.OpenTelemetry\AWS.Messaging.Telemetry.OpenTelemetry.csproj" /> | ||
<ProjectReference Include="..\..\src\AWS.Messaging\AWS.Messaging.csproj" /> | ||
</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,55 @@ | ||
using AWS.Messaging.Services.Backoff; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
using AWS.Messaging.Telemetry.OpenTelemetry; | ||
using OpenTelemetry.Resources; | ||
using OpenTelemetry.Trace; | ||
using Polly; | ||
using Polly.Retry; | ||
using PollyIntegration; | ||
using PollyIntegration.MessageHandlers; | ||
using PollyIntegration.Models; | ||
|
||
await Host.CreateDefaultBuilder(args) | ||
.ConfigureLogging(logging => | ||
{ | ||
logging.ClearProviders(); | ||
logging.AddConsole().SetMinimumLevel(LogLevel.Debug); | ||
}) | ||
.ConfigureAppConfiguration(configuration => | ||
{ | ||
configuration.AddJsonFile("appsettings.json"); | ||
}) | ||
.ConfigureServices((context, services) => | ||
{ | ||
services.AddResiliencePipeline("my-pipeline", builder => | ||
{ | ||
builder | ||
.AddRetry(new RetryStrategyOptions()) | ||
.AddTimeout(TimeSpan.FromSeconds(10)); | ||
}); | ||
services.TryAddSingleton<IBackoffHandler, PollyBackoffHandler>(); | ||
services.AddAWSMessageBus(builder => | ||
{ | ||
// To load the configuration from appsettings.json instead of the code below, uncomment this and remove the following lines. | ||
// builder.LoadConfigurationFromSettings(context.Configuration); | ||
builder.AddSQSPoller("https://sqs.us-west-2.amazonaws.com/012345678910/MPF"); | ||
builder.AddMessageHandler<ChatMessageHandler, ChatMessage>("chatMessage"); | ||
// Logging data messages is disabled by default to protect sensitive user data. If you want this enabled, uncomment the line below. | ||
// builder.EnableMessageContentLogging(); | ||
}) | ||
.AddOpenTelemetry() | ||
.ConfigureResource(resource => resource.AddService("PollyIntegration")) | ||
.WithTracing(tracing => tracing | ||
.AddAWSMessagingInstrumentation() | ||
.AddConsoleExporter()); | ||
}) | ||
.Build() | ||
.RunAsync(); |
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 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"AWS.Messaging": { | ||
"MessageHandlers": [ | ||
{ | ||
"HandlerType": "PollyIntegration.MessageHandlers.ChatMessageHandler", | ||
"MessageType": "PollyIntegration.Models.ChatMessage", | ||
"MessageTypeIdentifier": "chatMessage" | ||
} | ||
], | ||
"SQSPollers": [ | ||
{ | ||
"QueueUrl": "https://sqs.us-west-2.amazonaws.com/012345678910/MPF" | ||
} | ||
], | ||
"BackoffPolicy": "CappedExponential", | ||
"CappedExponentialBackoffOptions": { | ||
"CapBackoffTime": 2 | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
} | ||
} | ||
], | ||
"LogMessageContent": false | ||
"LogMessageContent": false, | ||
"BackoffPolicy": "CappedExponential" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"VisibilityTimeoutExtensionThreshold": 5 | ||
} | ||
} | ||
] | ||
], | ||
"BackoffPolicy": "CappedExponential" | ||
} | ||
} |
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
Oops, something went wrong.