-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discovery.AwsApi] Add Akka.Hosting extension methods (#818)
* Add Akka.Hosting extensions to EC2 * Add Akka.Hosting extension methods to ECS * Update ECS integration sample project * Bump .NET version from net5.0 to net6.0
- Loading branch information
Showing
13 changed files
with
345 additions
and
46 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
131 changes: 131 additions & 0 deletions
131
src/discovery/aws/Akka.Discovery.AwsApi/Ec2/AkkaHostingExtensions.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,131 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="AkkaHostingExtensions.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using Akka.Actor; | ||
using Akka.Hosting; | ||
|
||
namespace Akka.Discovery.AwsApi.Ec2 | ||
{ | ||
public static class AkkaHostingExtensions | ||
{ | ||
/// <summary> | ||
/// Adds Akka.Discovery.AwsApi.Ec2 support to the <see cref="ActorSystem"/>. | ||
/// Note that this only adds the discovery plugin, you will still need to add ClusterBootstrap for | ||
/// a complete solution. | ||
/// </summary> | ||
/// <param name="builder"> | ||
/// The builder instance being configured. | ||
/// </param> | ||
/// <returns> | ||
/// The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in. | ||
/// </returns> | ||
/// <example> | ||
/// <code> | ||
/// services.AddAkka("mySystem", builder => { | ||
/// builder | ||
/// .WithClustering() | ||
/// .WithClusterBootstrap(setup => | ||
/// { | ||
/// setup.ContactPointDiscovery.ServiceName = "testService"; | ||
/// setup.ContactPointDiscovery.RequiredContactPointsNr = 1; | ||
/// }, autoStart: true) | ||
/// .WithAwsEc2Discovery(); | ||
/// } | ||
/// </code> | ||
/// </example> | ||
public static AkkaConfigurationBuilder WithAwsEc2Discovery(this AkkaConfigurationBuilder builder) | ||
=> builder.WithAwsEc2Discovery(new Ec2ServiceDiscoverySetup()); | ||
|
||
/// <summary> | ||
/// Adds Akka.Discovery.AwsApi.Ec2 support to the <see cref="ActorSystem"/>. | ||
/// Note that this only adds the discovery plugin, you will still need to add ClusterBootstrap for | ||
/// a complete solution. | ||
/// </summary> | ||
/// <param name="builder"> | ||
/// The builder instance being configured. | ||
/// </param> | ||
/// <param name="configure"> | ||
/// An action that modifies an <see cref="Ec2ServiceDiscoverySetup"/> instance, used | ||
/// to configure Akka.Discovery.AwsApi.Ec2. | ||
/// </param> | ||
/// <returns> | ||
/// The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in. | ||
/// </returns> | ||
/// <example> | ||
/// <code> | ||
/// services.AddAkka("mySystem", builder => { | ||
/// builder | ||
/// .WithClustering() | ||
/// .WithClusterBootstrap(setup => | ||
/// { | ||
/// setup.ContactPointDiscovery.ServiceName = "testService"; | ||
/// setup.ContactPointDiscovery.RequiredContactPointsNr = 1; | ||
/// }, autoStart: true) | ||
/// .WithAwsEc2Discovery(setup => { | ||
/// setup.WithCredentialProvider<AnonymousEc2CredentialProvider>(); | ||
/// setup.TagKey = "myTag"; | ||
/// }); | ||
/// } | ||
/// </code> | ||
/// </example> | ||
public static AkkaConfigurationBuilder WithAwsEc2Discovery( | ||
this AkkaConfigurationBuilder builder, | ||
Action<Ec2ServiceDiscoverySetup> configure) | ||
{ | ||
var setup = new Ec2ServiceDiscoverySetup(); | ||
configure(setup); | ||
return builder.WithAwsEc2Discovery(setup); | ||
} | ||
|
||
/// <summary> | ||
/// Adds Akka.Discovery.AwsApi.Ec2 support to the <see cref="ActorSystem"/>. | ||
/// Note that this only adds the discovery plugin, you will still need to add ClusterBootstrap for | ||
/// a complete solution. | ||
/// </summary> | ||
/// <param name="builder"> | ||
/// The builder instance being configured. | ||
/// </param> | ||
/// <param name="setup"> | ||
/// The <see cref="Ec2ServiceDiscoverySetup"/> instance used to configure Akka.Discovery.Azure. | ||
/// </param> | ||
/// <returns> | ||
/// The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in. | ||
/// </returns> | ||
/// <example> | ||
/// <code> | ||
/// services.AddAkka("mySystem", builder => { | ||
/// builder | ||
/// .WithClustering() | ||
/// .WithClusterBootstrap(setup => | ||
/// { | ||
/// setup.ContactPointDiscovery.ServiceName = "testService"; | ||
/// setup.ContactPointDiscovery.RequiredContactPointsNr = 1; | ||
/// }, autoStart: true) | ||
/// .WithAwsEc2Discovery(setup => { | ||
/// setup.WithCredentialProvider<AnonymousEc2CredentialProvider>(); | ||
/// setup.TagKey = "myTag"; | ||
/// }); | ||
/// } | ||
/// </code> | ||
/// </example> | ||
public static AkkaConfigurationBuilder WithAwsEc2Discovery( | ||
this AkkaConfigurationBuilder builder, | ||
Ec2ServiceDiscoverySetup setup) | ||
{ | ||
builder.AddHocon("akka.discovery.method = aws-api-ec2-tag-based", HoconAddMode.Prepend); | ||
builder.AddSetup(setup); | ||
|
||
// force start the module | ||
builder.AddStartup((system, registry) => | ||
{ | ||
AwsEc2Discovery.Get(system); | ||
}); | ||
return builder; | ||
} | ||
} | ||
} |
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
153 changes: 153 additions & 0 deletions
153
src/discovery/aws/Akka.Discovery.AwsApi/Ecs/AkkaHostingExtensions.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,153 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="AkkaHostingExtensions.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2009-2022 Lightbend Inc. <http://www.lightbend.com> | ||
// Copyright (C) 2013-2022 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Akka.Actor; | ||
using Akka.Hosting; | ||
using Amazon.ECS.Model; | ||
|
||
namespace Akka.Discovery.AwsApi.Ecs | ||
{ | ||
public static class AkkaHostingExtensions | ||
{ | ||
/// <summary> | ||
/// Adds Akka.Discovery.AwsApi.Ecs support to the <see cref="ActorSystem"/>. | ||
/// Note that this only adds the discovery plugin, you will still need to add ClusterBootstrap for | ||
/// a complete solution. | ||
/// </summary> | ||
/// <param name="builder"> | ||
/// The builder instance being configured. | ||
/// </param> | ||
/// <param name="clusterName"> | ||
/// <para> | ||
/// Optional. The name of the AWS ECS cluster. | ||
/// </para> | ||
/// <b>Default</b>: "default" | ||
/// </param> | ||
/// <param name="tags"> | ||
/// <para> | ||
/// Optional. A list of <see cref="Tag"/> used to filter the ECS cluster tasks. | ||
/// The task must have the same exact list of tags to be considered as potential contact point by the | ||
/// discovery module. | ||
/// </para> | ||
/// <b>Default</b>: empty list. | ||
/// </param> | ||
/// <returns> | ||
/// The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in. | ||
/// </returns> | ||
/// <example> | ||
/// <code> | ||
/// services.AddAkka("mySystem", builder => { | ||
/// builder | ||
/// .WithClustering() | ||
/// .WithClusterBootstrap(setup => | ||
/// { | ||
/// setup.ContactPointDiscovery.ServiceName = "testService"; | ||
/// setup.ContactPointDiscovery.RequiredContactPointsNr = 1; | ||
/// }, autoStart: true) | ||
/// .WithAwsEcsDiscovery(); | ||
/// } | ||
/// </code> | ||
/// </example> | ||
public static AkkaConfigurationBuilder WithAwsEcsDiscovery( | ||
this AkkaConfigurationBuilder builder, | ||
string clusterName = null, | ||
IEnumerable<Tag> tags = null) | ||
=> builder.WithAwsEcsDiscovery(new EcsServiceDiscoverySetup | ||
{ | ||
Cluster = clusterName, | ||
Tags = tags | ||
}); | ||
|
||
/// <summary> | ||
/// Adds Akka.Discovery.AwsApi.Ec2 support to the <see cref="ActorSystem"/>. | ||
/// Note that this only adds the discovery plugin, you will still need to add ClusterBootstrap for | ||
/// a complete solution. | ||
/// </summary> | ||
/// <param name="builder"> | ||
/// The builder instance being configured. | ||
/// </param> | ||
/// <param name="configure"> | ||
/// An action that modifies an <see cref="EcsServiceDiscoverySetup"/> instance, used | ||
/// to configure Akka.Discovery.AwsApi.Ec2. | ||
/// </param> | ||
/// <returns> | ||
/// The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in. | ||
/// </returns> | ||
/// <example> | ||
/// <code> | ||
/// services.AddAkka("mySystem", builder => { | ||
/// builder | ||
/// .WithClustering() | ||
/// .WithClusterBootstrap(setup => | ||
/// { | ||
/// setup.ContactPointDiscovery.ServiceName = "testService"; | ||
/// setup.ContactPointDiscovery.RequiredContactPointsNr = 1; | ||
/// }, autoStart: true) | ||
/// .WithAwsEcsDiscovery(setup => { | ||
/// setup.Cluster = "my-ecs-cluster-name"; | ||
/// }); | ||
/// } | ||
/// </code> | ||
/// </example> | ||
public static AkkaConfigurationBuilder WithAwsEcsDiscovery( | ||
this AkkaConfigurationBuilder builder, | ||
Action<EcsServiceDiscoverySetup> configure) | ||
{ | ||
var setup = new EcsServiceDiscoverySetup(); | ||
configure(setup); | ||
return builder.WithAwsEcsDiscovery(setup); | ||
} | ||
|
||
/// <summary> | ||
/// Adds Akka.Discovery.AwsApi.Ec2 support to the <see cref="ActorSystem"/>. | ||
/// Note that this only adds the discovery plugin, you will still need to add ClusterBootstrap for | ||
/// a complete solution. | ||
/// </summary> | ||
/// <param name="builder"> | ||
/// The builder instance being configured. | ||
/// </param> | ||
/// <param name="setup"> | ||
/// The <see cref="EcsServiceDiscoverySetup"/> instance used to configure Akka.Discovery.Azure. | ||
/// </param> | ||
/// <returns> | ||
/// The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in. | ||
/// </returns> | ||
/// <example> | ||
/// <code> | ||
/// services.AddAkka("mySystem", builder => { | ||
/// builder | ||
/// .WithClustering() | ||
/// .WithClusterBootstrap(setup => | ||
/// { | ||
/// setup.ContactPointDiscovery.ServiceName = "testService"; | ||
/// setup.ContactPointDiscovery.RequiredContactPointsNr = 1; | ||
/// }, autoStart: true) | ||
/// .WithAwsEcsDiscovery(new EcsServiceDiscoverySetup { | ||
/// Cluster = "my-ecs-cluster-name" | ||
/// }); | ||
/// } | ||
/// </code> | ||
/// </example> | ||
public static AkkaConfigurationBuilder WithAwsEcsDiscovery( | ||
this AkkaConfigurationBuilder builder, | ||
EcsServiceDiscoverySetup setup) | ||
{ | ||
builder.AddHocon("akka.discovery.method = aws-api-ecs", HoconAddMode.Prepend); | ||
builder.AddSetup(setup); | ||
|
||
// force start the module | ||
builder.AddStartup((system, registry) => | ||
{ | ||
AwsEcsDiscovery.Get(system); | ||
}); | ||
return builder; | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.