Skip to content
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

Introduce New Types For Subscription Positions #188

Merged
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
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,39 @@ jobs:
dotnet restore
dotnet list package --vulnerable --include-transitive --framework ${{ matrix.framework }} | tee vulnerabilities.txt
! cat vulnerabilities.txt | grep -q "has the following vulnerable packages"
build-samples:
timeout-minutes: 5
runs-on: ubuntu-latest
services:
esdb:
image: ghcr.io/eventstore/eventstore:21.10.1-focal # TODO replace with LTS
env:
EVENTSTORE_INSECURE: true
EVENTSTORE_MEMDB: true
EVENTSTORE_RUN_PROJECTIONS: all
EVENTSTORE_START_STANDARD_PROJECTIONS: true
ports:
- 2113:2113
options: --health-cmd "exit 0"
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install netcoreapp3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x
- name: Install net5.0
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Compile
shell: bash
run: |
dotnet build samples
- name: Run
shell: bash
run: |
find samples/ -type f -iname "*.csproj" -print0 | xargs -0L1 dotnet run --project
build-dotnet:
timeout-minutes: 20
strategy:
Expand Down
16 changes: 13 additions & 3 deletions samples/appending-events/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@

namespace appending_events {
class Program {
static void Main(string[] args) {
using var client = new EventStoreClient(
EventStoreClientSettings.Create("esdb://admin:changeit@localhost:2113?TlsVerifyCert=false")
static async Task<int> Main(string[] args) {
var settings = EventStoreClientSettings.Create("esdb://localhost:2113?tls=false");
settings.OperationOptions.ThrowOnAppendFailure = false;
await using var client = new EventStoreClient(
settings
);
await AppendToStream(client);
await AppendWithConcurrencyCheck(client);
await AppendWithNoStream(client);
await AppendWithSameId(client);

return 0;
}

private static async Task AppendToStream(EventStoreClient client) {
Expand Down Expand Up @@ -90,6 +98,8 @@ await client.AppendToStreamAsync(
}

private static async Task AppendWithConcurrencyCheck(EventStoreClient client) {
await client.AppendToStreamAsync("concurrency-stream", StreamRevision.None,
new[] {new EventData(Uuid.NewUuid(), "-", ReadOnlyMemory<byte>.Empty)});
#region append-with-concurrency-check
var clientOneRead = client.ReadStreamAsync(
Direction.Forwards,
Expand Down
2 changes: 1 addition & 1 deletion samples/persistent-subscriptions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Program
{
static async Task Main(string[] args) {
await using var client = new EventStorePersistentSubscriptionsClient(
EventStoreClientSettings.Create("esdb://admin:changeit@localhost:2113?TlsVerifyCert=false")
EventStoreClientSettings.Create("esdb://localhost:2113?tls=false")
);
await CreatePersistentSubscription(client);
await ConnectToPersistentSubscriptionToStream(client);
Expand Down
21 changes: 12 additions & 9 deletions samples/quick-start/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public class TestEvent {
}

class Program {
static async Task Main(string[] args) {
static void Main(string[] args) {
}

static async Task Samples() {
CancellationTokenSource tokenSource = new CancellationTokenSource();
CancellationToken cancellationToken = tokenSource.Token;

Expand Down Expand Up @@ -61,14 +64,14 @@ await client.AppendToStreamAsync(
#endregion overriding-user-credentials

#region readStream
var result = client.ReadStreamAsync(
Direction.Forwards,
"some-stream",
StreamPosition.Start,
cancellationToken: cancellationToken);
var result = client.ReadStreamAsync(
Direction.Forwards,
"some-stream",
StreamPosition.Start,
cancellationToken: cancellationToken);

var events = await result.ToListAsync(cancellationToken);
#endregion readStream
}
var events = await result.ToListAsync(cancellationToken);
#endregion readStream
}
}
}
2 changes: 1 addition & 1 deletion samples/reading-events/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace reading_events {
class Program {
static async Task Main(string[] args) {
using var client = new EventStoreClient(
EventStoreClientSettings.Create("esdb://admin:changeit@localhost:2113?TlsVerifyCert=false")
EventStoreClientSettings.Create("esdb://localhost:2113?tls=false")
);

var events = Enumerable.Range(0, 20)
Expand Down
2 changes: 1 addition & 1 deletion samples/secure-with-tls/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Program
static async Task Main(string[] args)
{
// take the address from environment variable (when run with Docker) or use localhost by default
var connectionString = Environment.GetEnvironmentVariable("ESDB_CONNECTION_STRING") ?? "esdb://localhost:2113?Tls=true";
var connectionString = Environment.GetEnvironmentVariable("ESDB_CONNECTION_STRING") ?? "esdb://localhost:2113?tls=false";

Console.WriteLine($"Connecting to EventStoreDB at: `{connectionString}`");

Expand Down
32 changes: 17 additions & 15 deletions samples/server-side-filtering/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -11,13 +9,17 @@
namespace server_side_filtering {
class Program {
static async Task Main() {
using var client = new EventStoreClient(
EventStoreClientSettings.Create("esdb://localhost:2113?Tls=false")
const int eventCount = 100;
var semaphore = new SemaphoreSlim(eventCount);

await using var client = new EventStoreClient(
EventStoreClientSettings.Create("esdb://localhost:2113?tls=false")
);

await client.SubscribeToAllAsync(Position.Start,
await client.SubscribeToAllAsync(FromAll.Start,
(s, e, c) => {
Console.WriteLine($"{e.Event.EventType} @ {e.Event.Position.PreparePosition}");
semaphore.Release();
return Task.CompletedTask;
},
filterOptions: new SubscriptionFilterOptions(
Expand All @@ -29,9 +31,9 @@ await client.SubscribeToAllAsync(Position.Start,
})
);

Thread.Sleep(2000);
await Task.Delay(2000);

for (var i = 0; i < 100; i++) {
for (var i = 0; i < eventCount; i++) {
var eventData = new EventData(
Uuid.NewUuid(),
i % 2 == 0 ? "some-event" : "other-event",
Expand All @@ -45,12 +47,12 @@ await client.AppendToStreamAsync(
);
}

Console.ReadLine();
await semaphore.WaitAsync();
}

private static async Task ExcludeSystemEvents(EventStoreClient client) {
#region exclude-system
await client.SubscribeToAllAsync(Position.Start,
await client.SubscribeToAllAsync(FromAll.Start,
(s, e, c) => {
Console.WriteLine(
$"{e.Event.EventType} @ {e.Event.Position.PreparePosition}");
Expand All @@ -68,7 +70,7 @@ private static async Task EventTypePrefix(EventStoreClient client) {
EventTypeFilter.Prefix("customer-"));
#endregion event-type-prefix

await client.SubscribeToAllAsync(Position.Start,
await client.SubscribeToAllAsync(FromAll.Start,
(s, e, c) => {
Console.WriteLine(
$"{e.Event.EventType} @ {e.Event.Position.PreparePosition}");
Expand All @@ -84,7 +86,7 @@ private static async Task EventTypeRegex(EventStoreClient client) {
EventTypeFilter.RegularExpression("^user|^company"));
#endregion event-type-regex

await client.SubscribeToAllAsync(Position.Start,
await client.SubscribeToAllAsync(FromAll.Start,
(s, e, c) => {
Console.WriteLine(
$"{e.Event.EventType} @ {e.Event.Position.PreparePosition}");
Expand All @@ -100,7 +102,7 @@ private static async Task StreamPrefix(EventStoreClient client) {
StreamFilter.Prefix("user-"));
#endregion stream-prefix

await client.SubscribeToAllAsync(Position.Start,
await client.SubscribeToAllAsync(FromAll.Start,
(s, e, c) => {
Console.WriteLine(
$"{e.Event.EventType} @ {e.Event.Position.PreparePosition}");
Expand All @@ -116,7 +118,7 @@ private static async Task StreamRegex(EventStoreClient client) {
StreamFilter.RegularExpression("^account|^savings"));
#endregion stream-regex

await client.SubscribeToAllAsync(Position.Start,
await client.SubscribeToAllAsync(FromAll.Start,
(s, e, c) => {
Console.WriteLine(
$"{e.Event.EventType} @ {e.Event.Position.PreparePosition}");
Expand All @@ -137,7 +139,7 @@ private static async Task CheckpointCallback(EventStoreClient client) {
});
#endregion checkpoint

await client.SubscribeToAllAsync(Position.Start,
await client.SubscribeToAllAsync(FromAll.Start,
(s, e, c) => {
Console.WriteLine(
$"{e.Event.EventType} @ {e.Event.Position.PreparePosition}");
Expand All @@ -159,7 +161,7 @@ private static async Task CheckpointCallbackWithInterval(EventStoreClient client
});
#endregion checkpoint-with-interval

await client.SubscribeToAllAsync(Position.Start,
await client.SubscribeToAllAsync(FromAll.Start,
(s, e, c) => {
Console.WriteLine(
$"{e.Event.EventType} @ {e.Event.Position.PreparePosition}");
Expand Down
8 changes: 6 additions & 2 deletions samples/setting-up-dependency-injection/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace setting_up_dependency_injection {
public class Program {
public static void Main(string[] args) {
CreateHostBuilder(args).Build().Run();
public static async Task Main(string[] args) {
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));
await CreateHostBuilder(args).Build().WaitForShutdownAsync(cts.Token);
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Expand Down
2 changes: 1 addition & 1 deletion samples/setting-up-dependency-injection/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void ConfigureServices(IServiceCollection services) {
services.AddControllers();

#region setting-up-dependency
services.AddEventStoreClient("esdb://admin:changeit@localhost:2113?TlsVerifyCert=false");
services.AddEventStoreClient("esdb://admin:changeit@localhost:2113?tls=false");
#endregion setting-up-dependency
}

Expand Down
Loading