-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 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
42 changes: 42 additions & 0 deletions
42
src/Proto.Cluster.SeedNode.MongoDb/MongoDbSeedNodeDiscovery.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,42 @@ | ||
using MongoDB.Driver; | ||
using Proto.Cluster.Seed; | ||
|
||
namespace Proto.Cluster.SeedNode.MongoDb; | ||
|
||
public class MongoDbSeedNodeDiscovery : ISeedNodeDiscovery | ||
{ | ||
private readonly IMongoCollection<ProtoActorMember> _collection; | ||
|
||
public MongoDbSeedNodeDiscovery(IMongoDatabase mongoDatabase, string storageKey = "ProtoActorMembers") | ||
{ | ||
_collection = mongoDatabase.GetCollection<ProtoActorMember>(storageKey); | ||
} | ||
|
||
public async Task Register(string memberId, string host, int port) | ||
{ | ||
await _collection.InsertOneAsync(new ProtoActorMember | ||
{ | ||
MemberId = memberId, | ||
Host = host, | ||
Port = port | ||
}); | ||
} | ||
|
||
public async Task Remove(string memberId) | ||
{ | ||
await _collection.DeleteOneAsync(x => x.MemberId == memberId); | ||
} | ||
|
||
public async Task<(string memberId, string host, int port)[]> GetAll() | ||
{ | ||
var mongoResult = await _collection | ||
.Find(_ => true) | ||
.ToListAsync(); | ||
|
||
var result = mongoResult | ||
.Select(x => (x.MemberId, x.Host, x.Port)) | ||
.ToArray(); | ||
|
||
return result; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Proto.Cluster.SeedNode.MongoDb/Proto.Cluster.SeedNode.MongoDb.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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<IsPackable>true</IsPackable> | ||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MongoDB.Driver" Version="2.20.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Proto.Cluster\Proto.Cluster.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,13 @@ | ||
using MongoDB.Bson.Serialization.Attributes; | ||
|
||
namespace Proto.Cluster.SeedNode.MongoDb; | ||
|
||
public class ProtoActorMember | ||
{ | ||
[BsonId] | ||
private string? Id { get; set; } | ||
|
||
public string MemberId { get; set; } = ""; | ||
public string Host { get; set; } = ""; | ||
public int Port { get; set; } = int.MinValue; | ||
} |