For GRPC
download the zip file from https://www.eventstore.com/downloads and unzip into a local folder
or install eventstore-oss
from choco
for version 20.10 run
EventStore.ClusterNode.exe --insecure --run-projections=all --start-standard-projections --enable-atom-pub-over-http
Open localhost:2113
in a browser and confirm the db is running
Use connection string esdb://localhost:2113?Tls=false
for gRPC clients.
.net 3.1 console app
es-connect.csproj
file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EventStore.Client.Grpc.Streams" Version="20.6.1" />
</ItemGroup>
</Project>
main.cs
file
using EventStore.Client;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace connections
{
class Program
{
public static async Task Main()
{
var settings = EventStoreClientSettings.Create("esdb://localhost:2113?tls=false");
var client = new EventStoreClient(settings);
var itemId = Guid.NewGuid();
var streamName = $"item-{itemId}";
var eventData1 = new EventData(
Uuid.NewUuid(), //event id
"ItemCreated", //event type name
Encoding.UTF8.GetBytes($@"{{""item-id"": ""{itemId}"", ""a-starting-value"": ""foo""}}"), //event data
Encoding.UTF8.GetBytes($@"{{""written-by"": ""me"", ""written-at"":""{DateTime.UtcNow}""}}") // event metadata
);
var eventData2 = new EventData(
Uuid.NewUuid(), //event id
"ItemChanged", //event type name
Encoding.UTF8.GetBytes($@"{{""item-id"": ""{itemId}"", ""a-new-value"": ""foo""}}"), //event data
Encoding.UTF8.GetBytes($@"{{""written-by"": ""me"", ""written-at"":""{DateTime.UtcNow}""}}") // event metadata
);
var rslt = await client.AppendToStreamAsync(
streamName,
StreamState.NoStream,
new List<EventData> { eventData1,eventData2 });
Console.WriteLine($"Wrote events through number {rslt.NextExpectedStreamRevision} at {rslt.LogPosition}");
Console.WriteLine();
var events = client.ReadStreamAsync(Direction.Forwards, streamName, StreamPosition.Start, 100);
await foreach (var @event in events)
{
Console.WriteLine($"Event Postion:{@event.OriginalEvent.Position}");
Console.WriteLine($"Event Number:{@event.OriginalEventNumber}");
Console.WriteLine($"Event Id:{@event.OriginalEvent.EventId}");
Console.WriteLine($"data:{Encoding.UTF8.GetString(@event.Event.Data.Span)}");
Console.WriteLine($"metadata:{Encoding.UTF8.GetString(@event.Event.Metadata.Span)}");
Console.WriteLine();
}
}
}
}
browse to http://localhost:2113/web/index.html#/streams
to confirm the written stream(s).
Click the links for the stream details
e.g. http://localhost:2113/web/index.html#/streams/item-{item id}
and http://localhost:2113/web/index.html#/streams/item-{item id}\0
for the first event
the item category is at http://localhost:2113/web/index.html#/streams/$ce-item
the ItemCreated events at http://localhost:2113/web/index.html#/streams/$et-ItemCreated
the ItemChanged events at http://localhost:2113/web/index.html#/streams/$et-ItemChanged