-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve Akka.Remote host binding issue #37
Merged
Aaronontheweb
merged 2 commits into
akkadotnet:dev
from
Aaronontheweb:fix-remote-binding
Apr 10, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 16 additions & 0 deletions
16
src/Akka.Remote.Hosting.Tests/Akka.Remote.Hosting.Tests.csproj
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>$(TestsNetCoreFramework)</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.6.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" /> | ||
<PackageReference Include="xunit" Version="$(XunitVersion)" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Akka.Remote.Hosting\Akka.Remote.Hosting.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,32 @@ | ||
using System.Threading.Tasks; | ||
using Akka.Actor; | ||
using Akka.Hosting; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Xunit; | ||
|
||
namespace Akka.Remote.Hosting.Tests; | ||
|
||
public class RemoteConfigurationSpecs | ||
{ | ||
[Fact] | ||
public async Task AkkaRemoteShouldUsePublicHostnameCorrectly() | ||
{ | ||
// arrange | ||
using var host = new HostBuilder().ConfigureServices(services => | ||
{ | ||
services.AddAkka("RemoteSys", (builder, provider) => | ||
{ | ||
builder.WithRemoting("0.0.0.0", 0, "localhost"); | ||
}); | ||
}).Build(); | ||
|
||
// act | ||
await host.StartAsync(); | ||
ExtendedActorSystem actorSystem = (ExtendedActorSystem)host.Services.GetRequiredService<ActorSystem>(); | ||
|
||
// assert | ||
actorSystem.Provider.DefaultAddress.Host.Should().Be("localhost"); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,6 +8,11 @@ public static class AkkaRemoteHostingExtensions | |
{ | ||
private static AkkaConfigurationBuilder BuildRemoteHocon(this AkkaConfigurationBuilder builder, string hostname, int port, string publicHostname = null, int? publicPort = null) | ||
{ | ||
if (string.IsNullOrEmpty(publicHostname)) | ||
{ | ||
publicHostname = hostname; | ||
hostname = "0.0.0.0"; // bind to all addresses by default | ||
} | ||
var config = $@" | ||
akka.remote.dot-netty.tcp.hostname = ""{hostname}"" | ||
akka.remote.dot-netty.tcp.public-hostname = ""{publicHostname ?? hostname}"" | ||
|
@@ -30,7 +35,7 @@ private static AkkaConfigurationBuilder BuildRemoteHocon(this AkkaConfigurationB | |
/// <returns>The same <see cref="AkkaConfigurationBuilder"/> instance originally passed in.</returns> | ||
public static AkkaConfigurationBuilder WithRemoting(this AkkaConfigurationBuilder builder, string hostname, int port, string publicHostname = null, int? publicPort = null) | ||
{ | ||
var hoconBuilder = BuildRemoteHocon(builder, hostname, port); | ||
var hoconBuilder = BuildRemoteHocon(builder, hostname, port, publicHostname, publicPort); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the fix - forgot to pass in the parameters to the |
||
|
||
if (builder.ActorRefProvider.HasValue) | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided to resolve a potential papercut for most users here - have the system bind, by default, to a reachable socket and alias using the hostname if a
publicHostname
isn't explicitly specified. Means that most K8s / Docker scenarios should "just work" with these changes.