Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"DOTNET_NOLOGO": "true"
},
"onCreateCommand": "chmod +x /workspaces/developer-bootcamp/polyglot-persistence/onCreateCommand.sh && /workspaces/developer-bootcamp/polyglot-persistence/onCreateCommand.sh",
"postCreateCommand": "chmod +x /workspaces/developer-bootcamp/polyglot-persistence/postCreateCommand.sh && /workspaces/developer-bootcamp/polyglot-persistence/postCreateCommand.sh",
"forwardPorts": [27017, 5432, 6379, 2113, 1113],
"portsAttributes": {
"2113": {
Expand Down
14 changes: 0 additions & 14 deletions polyglot-persistence/.devcontainer/Dockerfile

This file was deleted.

14 changes: 0 additions & 14 deletions polyglot-persistence/.devcontainer/devcontainer.json

This file was deleted.

2 changes: 1 addition & 1 deletion polyglot-persistence/Common/Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions polyglot-persistence/DemoWeb/PostgresService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class PostgresService
public PostgresService(IConfiguration configuration, ILogger<PostgresService> logger)
{
_logger = logger;
_connectionString = configuration.GetConnectionString("PostgreSQL")
?? "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=postgres";
var postgresHost = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "localhost";
_connectionString = $"Host={postgresHost};Port=5432;Database=postgres;Username=postgres;Password=postgres";

_logger.LogInformation("PostgreSQL connection string: {ConnectionString}",
_connectionString.Replace("Password=", "Password=***"));
Expand Down
7 changes: 5 additions & 2 deletions polyglot-persistence/DemoWeb/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
builder.Services.AddSignalR();

// Register Redis services
var redisHost = Environment.GetEnvironmentVariable("REDIS_HOST") ?? "localhost";
builder.Services.AddSingleton<IConnectionMultiplexer>(sp =>
ConnectionMultiplexer.Connect("localhost:6379"));
ConnectionMultiplexer.Connect($"{redisHost}:6379"));
builder.Services.AddSingleton<RedisService>();

// Register PostgreSQL service
Expand Down Expand Up @@ -44,4 +45,6 @@
// Map SignalR hub
app.MapHub<TopProductsHub>("/topProductsHub");

app.Run();
app.Run();

Console.WriteLine($"{AppDomain.CurrentDomain.FriendlyName} started");
4 changes: 2 additions & 2 deletions polyglot-persistence/DemoWeb/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5108",
"applicationUrl": "http://0.0.0.0:5108",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand All @@ -22,7 +22,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7164;http://localhost:5108",
"applicationUrl": "https://0.0.0.0:7164;http://0.0.0.0:5108",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
3 changes: 0 additions & 3 deletions polyglot-persistence/DemoWeb/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"ConnectionStrings": {
"PostgreSQL": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=postgres"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
6 changes: 4 additions & 2 deletions polyglot-persistence/MongoProjection/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
Console.WriteLine($"{AppDomain.CurrentDomain.FriendlyName} started");

// Connect to MongoDB
var mongoCollection = new MongoClient("mongodb://localhost:27017").GetDatabase("polyglot-persistence").GetCollection<BsonDocument>("total-payment");
var mongoHost = Environment.GetEnvironmentVariable("MONGO_HOST") ?? "localhost";
var mongoCollection = new MongoClient($"mongodb://{mongoHost}:27017").GetDatabase("polyglot-persistence").GetCollection<BsonDocument>("total-payment");

// Connect to EventStoreDB
var esdb = new EventStoreClient(EventStoreClientSettings.Create("esdb://admin:changeit@localhost:2113?tls=false"));
var esdbHost = Environment.GetEnvironmentVariable("ESDB_HOST") ?? "localhost";
var esdb = new EventStoreClient(EventStoreClientSettings.Create($"esdb://admin:changeit@{esdbHost}:2113?tls=false"));

var checkpointValue = mongoCollection // Get the checkpoint value from MongoDB..
.Find(Builders<BsonDocument>.Filter.Eq("_id", "total")) // from the total document's..
Expand Down
7 changes: 5 additions & 2 deletions polyglot-persistence/PostgresProjection/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
// Connect to PostgreSQL and EventStoreDB //
// -------------------------------------- //

var postgres = new PostgresDataAccess(new NpgsqlConnection("Host=localhost;Port=5432;Database=postgres;Username=postgres"));
var esdb = new EventStoreClient(EventStoreClientSettings.Create("esdb://admin:changeit@localhost:2113?tls=false"));
var postgresHost = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "localhost";
var postgres = new PostgresDataAccess(new NpgsqlConnection($"Host={postgresHost};Port=5432;Database=postgres;Username=postgres"));

var esdbHost = Environment.GetEnvironmentVariable("ESDB_HOST") ?? "localhost";
var esdb = new EventStoreClient(EventStoreClientSettings.Create($"esdb://admin:changeit@{esdbHost}:2113?tls=false"));

postgres.Execute(CartProjection.GetCreateCartTableCommand()); // Create the checkpoint table if it doesn't exist
postgres.Execute(Checkpoint.GetCreateTableCommand()); // Create the checkpoint table if it doesn't exist
Expand Down
8 changes: 6 additions & 2 deletions polyglot-persistence/RedisProjection/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

Console.WriteLine($"{AppDomain.CurrentDomain.FriendlyName} started");

var redis = ConnectionMultiplexer.Connect("localhost:6379").GetDatabase(); // Connect to Redis
var esdb = new EventStoreClient(EventStoreClientSettings.Create("esdb://admin:changeit@localhost:2113?tls=false")); // Connect to EventStoreDB
// Program.cs
var redisHost = Environment.GetEnvironmentVariable("REDIS_HOST") ?? "localhost";
var redis = ConnectionMultiplexer.Connect($"{redisHost}:6379").GetDatabase();
// Connect to Redis
var esdbHost = Environment.GetEnvironmentVariable("ESDB_HOST") ?? "localhost";
var esdb = new EventStoreClient(EventStoreClientSettings.Create($"esdb://admin:changeit@{esdbHost}:2113?tls=false")); // Connect to EventStoreDB

var checkpointValue = redis.StringGet("checkpoint"); // Get the checkpoint value from redis
var streamPosition = long.TryParse(checkpointValue, out var checkpoint) // Check if it exists and convertible to long
Expand Down
79 changes: 79 additions & 0 deletions polyglot-persistence/docker-compose.codespaces-prebuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
services:
mongo:
image: mongo:7.0
container_name: mongo
ports:
- "27017:27017"

postgres:
image: postgres:16
container_name: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_HOST_AUTH_METHOD=trust

redis:
image: redis:7.2
container_name: redis
ports:
- "6379:6379"

eventstore:
image: eventstore/eventstore:24.10
container_name: eventstore
ports:
- "2113:2113"
- "1113:1113"
environment:
- EVENTSTORE_RUN_PROJECTIONS=All
- EVENTSTORE_START_STANDARD_PROJECTIONS=true
- EVENTSTORE_INSECURE=true
- EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP=true

demoweb:
image: mcr.microsoft.com/dotnet/sdk:9.0
container_name: demoweb
working_dir: /app
volumes:
- ./DemoWeb:/app # Mount the DemoWeb project directory
command: ["dotnet", "build"]
ports:
- "5108:5108"
environment:
- REDIS_HOST=redis
- POSTGRES_HOST=postgres

postgresprojection:
image: mcr.microsoft.com/dotnet/sdk:9.0
container_name: postgresprojection
working_dir: /app
volumes:
- ./:/app
command: ["dotnet", "build", "./PostgresProjection"]
environment:
- POSTGRES_HOST=postgres
- ESDB_HOST=eventstore

redisprojection:
image: mcr.microsoft.com/dotnet/sdk:9.0
container_name: redisprojection
working_dir: /app
volumes:
- ./:/app
command: ["dotnet", "build", "./RedisProjection"]
environment:
- REDIS_HOST=redis
- ESDB_HOST=eventstore

mongoprojection:
image: mcr.microsoft.com/dotnet/sdk:9.0
container_name: mongoprojection
working_dir: /app
volumes:
- ./:/app
command: ["dotnet", "build", "./MongoProjection"]
environment:
- MONGO_HOST=mongo
- ESDB_HOST=eventstore

63 changes: 59 additions & 4 deletions polyglot-persistence/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ services:
container_name: mongo
ports:
- "27017:27017"

postgres:
image: postgres:16
container_name: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_HOST_AUTH_METHOD=trust

redis:
image: redis:7.2
container_name: redis
ports:
- "6379:6379"

eventstore:
image: eventstore/eventstore:24.10
container_name: eventstore
Expand All @@ -29,4 +29,59 @@ services:
- EVENTSTORE_RUN_PROJECTIONS=All
- EVENTSTORE_START_STANDARD_PROJECTIONS=true
- EVENTSTORE_INSECURE=true
- EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP=true
- EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP=true

demoweb:
image: mcr.microsoft.com/dotnet/sdk:9.0
container_name: demoweb
working_dir: /app
volumes:
- ./DemoWeb:/app # Mount the DemoWeb project directory
command: ["dotnet", "run"]
ports:
- "5108:5108"
environment:
- REDIS_HOST=redis
- POSTGRES_HOST=postgres

postgresprojection:
image: mcr.microsoft.com/dotnet/sdk:9.0
container_name: postgresprojection
working_dir: /app
volumes:
- ./:/app
command: ["dotnet", "run", "--project", "./PostgresProjection"]
environment:
- POSTGRES_HOST=postgres
- ESDB_HOST=eventstore
depends_on:
- postgres
- eventstore

redisprojection:
image: mcr.microsoft.com/dotnet/sdk:9.0
container_name: redisprojection
working_dir: /app
volumes:
- ./:/app
command: ["dotnet", "run", "--project", "./RedisProjection"]
environment:
- REDIS_HOST=redis
- ESDB_HOST=eventstore
depends_on:
- redis
- eventstore

mongoprojection:
image: mcr.microsoft.com/dotnet/sdk:9.0
container_name: mongoprojection
working_dir: /app
volumes:
- ./:/app
command: ["dotnet", "run", "--project", "./MongoProjection"]
environment:
- MONGO_HOST=mongo
- ESDB_HOST=eventstore
depends_on:
- mongo
- eventstore
20 changes: 20 additions & 0 deletions polyglot-persistence/generate-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
unzip -o /workspaces/developer-bootcamp/polyglot-persistence/data/commerce-data-set.zip -d /workspaces/developer-bootcamp/polyglot-persistence/

chmod +x /workspaces/developer-bootcamp/polyglot-persistence/tools/Kurrent.Extensions.Commerce/linux-x64/edb-commerce

# Wait for EventStoreDB to be ready
echo "Waiting for EventStoreDB to be ready..."
max_attempts=30
attempt=0
while ! curl -s http://localhost:2113/ > /dev/null; do
attempt=$((attempt+1))
if [ $attempt -eq $max_attempts ]; then
echo "EventStoreDB failed to start after $max_attempts attempts. Exiting."
exit 1
fi
echo "Waiting for EventStoreDB to be ready... (attempt $attempt/$max_attempts)"
sleep 2
done
echo "EventStoreDB is ready."

/workspaces/developer-bootcamp/polyglot-persistence/tools/Kurrent.Extensions.Commerce/linux-x64/edb-commerce seed-data-set /workspaces/developer-bootcamp/polyglot-persistence/data.json
Loading