Skip to content

Commit

Permalink
Clean up RethinkDB change feed implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tpeczek committed Sep 29, 2023
1 parent 816748e commit fdc0313
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 102 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/01-exposing-rethinkdb-change-feed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@ jobs:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
deploymentName: exposing-rethinkdb-change-feed
template: ./infrastructure/exposing-rethinkdb-change-feed.bicep
- name: Azure Logout
run: |
az logout
az cache purge
az account clear
deploy-webapp:
runs-on: ubuntu-latest
needs: deploy-infrastructure
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup .NET 7.0 SDK
uses: actions/[email protected]
with:
dotnet-version: '7.0.x'
- name: Restore
run: dotnet restore ./src/Demo.AspNetCore.Changefeed
- name: Build
run: dotnet build ./src/Demo.AspNetCore.Changefeed --configuration Release --no-restore
- name: Publish
run: dotnet publish ./src/Demo.AspNetCore.Changefeed --configuration Release --no-build --output ${DOTNET_ROOT}/app-exposing-change-feed
- name: Azure Login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Deploy
uses: azure/webapps-deploy@v2
with:
app-name: app-exposing-change-feed
package: ${{env.DOTNET_ROOT}}/app-exposing-change-feed
- name: Azure Logout
run: |
az logout
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="RethinkDb.Driver" Version="2.3.23" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="RethinkDb.Driver" Version="2.3.150" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Demo.AspNetCore.Changefeed.Services.Abstractions\Demo.AspNetCore.Changefeed.Services.Abstractions.csproj" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class RethinkDbOptions
{
public string HostnameOrIp { get; set; }
public string Hostname { get; set; }

public int? DriverPort { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Demo.AspNetCore.Changefeed.Services.Abstractions;
Expand All @@ -7,21 +8,25 @@ namespace Demo.AspNetCore.Changefeed.Services.RethinkDb
{
public static class RethinkDbServiceCollectionExtensions
{
public static IServiceCollection AddRethinkDb(this IServiceCollection services, Action<RethinkDbOptions> configureOptions)
private const string HOSTNAME_CONFIGURATION_KEY = "RethinkDb:Hostname";

public static IServiceCollection AddRethinkDb(this IServiceCollection services, IConfiguration configuration)
{
if (services == null)
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

if (configureOptions == null)
if (configuration is null)
{
throw new ArgumentNullException(nameof(configureOptions));
throw new ArgumentNullException(nameof(configuration));
}

services.Configure(configureOptions);
services.TryAddSingleton<IRethinkDbSingletonProvider, RethinkDbSingletonProvider>();
services.TryAddTransient<IThreadStatsChangefeedDbService, ThreadStatsRethinkDbService>();
services.Configure<RethinkDbOptions>(options =>
{
options.Hostname = configuration[HOSTNAME_CONFIGURATION_KEY];
});
services.TryAddSingleton<IThreadStatsChangefeedDbService, ThreadStatsRethinkDbService>();

return services;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using RethinkDb.Driver.Net;
using Demo.AspNetCore.Changefeed.Services.Abstractions;

namespace Demo.AspNetCore.Changefeed.Services.RethinkDb
{
internal class ThreadStatsRethinkDbService : IThreadStatsChangefeedDbService
internal class ThreadStatsRethinkDbService : IThreadStatsChangefeedDbService, IDisposable
{
private const string DATABASE_NAME = "Demo_AspNetCore_Changefeed_RethinkDB";
private const string THREAD_STATS_TABLE_NAME = "ThreadStats";

private readonly RethinkDbOptions _options;
private readonly global::RethinkDb.Driver.RethinkDB _rethinkDbSingleton;
private readonly Connection _rethinkDbConnection;

public ThreadStatsRethinkDbService(IRethinkDbSingletonProvider rethinkDbSingletonProvider)
private bool _disposed = false;

public ThreadStatsRethinkDbService(IOptions<RethinkDbOptions> options)
{
if (rethinkDbSingletonProvider == null)
_options = options?.Value ?? throw new ArgumentNullException(nameof(options));

_rethinkDbSingleton = global::RethinkDb.Driver.RethinkDB.R;

var rethinkDbConnectionBuilder = _rethinkDbSingleton.Connection().Hostname(options.Value.Hostname);

if (_options.DriverPort.HasValue)
{
rethinkDbConnectionBuilder.Port(options.Value.DriverPort.Value);
}

if (_options.Timeout.HasValue)
{
throw new ArgumentNullException(nameof(rethinkDbSingletonProvider));
rethinkDbConnectionBuilder.Timeout(options.Value.Timeout.Value);
}

_rethinkDbSingleton = rethinkDbSingletonProvider.RethinkDbSingleton;
_rethinkDbConnection = rethinkDbSingletonProvider.RethinkDbConnection;
_rethinkDbConnection = rethinkDbConnectionBuilder.Connect();
}

public Task EnsureDatabaseCreatedAsync()
Expand Down Expand Up @@ -55,5 +69,17 @@ public async Task<IChangefeed<ThreadStats>> GetThreadStatsChangefeedAsync(Cancel
await _rethinkDbSingleton.Db(DATABASE_NAME).Table(THREAD_STATS_TABLE_NAME).Changes().RunChangesAsync<ThreadStats>(_rethinkDbConnection, cancellationToken)
);
}

public void Dispose()
{
if (!_disposed)
{
_rethinkDbConnection.Dispose();

GC.SuppressFinalize(this);

_disposed = true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ public static IServiceCollection AddChangefeed(this IServiceCollection services,
{
switch (configuration.GetChangefeedService())
{
case ChangefeedServices.RethinkDb:
services.AddRethinkDb(configuration);
break;
case ChangefeedServices.AzureCosmos:
services.AddCosmos(configuration);
break;
case ChangefeedServices.AzureStorageBlobs:
services.AddBlob(configuration);
break;
case ChangefeedServices.Mongo:
services.AddMongo(configuration);
break;
case ChangefeedServices.RethinkDb:
services.AddRethinkDb(options =>
{
options.HostnameOrIp = "127.0.0.1";
});
case ChangefeedServices.AzureStorageBlobs:
services.AddBlob(configuration);
break;
default:
throw new NotSupportedException($"Not supported changefeed type.");
Expand Down
11 changes: 7 additions & 4 deletions src/Demo.AspNetCore.Changefeed/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
}
},
"AllowedHosts": "*",
"ChangefeedService": "[AzureCosmos|AzureStorageBlobs|Mongo]",
"ChangefeedService": "[RethinkDb|AzureCosmos|Mongo|AzureStorageBlobs]",
"RethinkDb": {
"Hostname": "[Enter RethinkDB hostname here]"
},
"AzureCosmos": {
"DocumentEndpoint": "[Enter Azure Cosmos DB document endpoint here]"
},
"AzureStorageBlobs": {
"ServiceUri": "[Enter Azure Blob Storage resource URI here]"
},
"Mongo": {
"ConnectionString": "[Enter MongoDB connection string here]"
},
"AzureStorageBlobs": {
"ServiceUri": "[Enter Azure Blob Storage resource URI here]"
}
}

0 comments on commit fdc0313

Please sign in to comment.