c# - 有没有一种方法可以启动Windows中提供的EventStore(根本不需要使用docker)?

标签 c# .net event-sourcing eventstoredb

我在玩EventStore。作为.NET用户,我更喜欢Windows作为OS,只有我拥有家庭版。为了安装Docker,我需要Windows专业版-但我没有它...这超出了我的预算。
无论如何,我一直尝试安装(通过Chocolatey)并进行管理。我该如何开始呢?我在文档中找不到该命令。
我有此代码:

var settings = new EventStoreClientSettings {
    ConnectivitySettings = {
        Address = new Uri("http://localhost:2113")
    }
};

var client = new EventStoreClient(settings);
取自here
我是一个错误“启动gRPC调用时出错-无法创建连接”。
我怀疑我需要启动服务器。但是如何?即使我使用docker,我仍然无法使用命令行启动服务器,因为我的经验告诉我,在这种情况下我会这样做。
我很乐意与他们联系,但我只是在探索-我没有此软件的许可证。

最佳答案

对于GRPC
https://www.eventstore.com/downloads下载zip文件,并将其解压缩到本地文件夹中
或从choco安装eventstore-oss对于版本20.10运行EventStore.ClusterNode.exe --insecure --run-projections=all --start-standard-projections --enable-atom-pub-over-http在浏览器中打开localhost:2113并确认数据库正在运行
将连接字符串esdb://localhost:2113?Tls=false用于gRPC客户端。
.net 3.1控制台应用程序es-connect.csproj文件

<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文件
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();
            }

        }
    }
}
浏览至http://localhost:2113/web/index.html#/streams以确认编写的流。
单击链接以获取流的详细信息
例如http://localhost:2113/web/index.html#/streams/item-{item id}http://localhost:2113/web/index.html#/streams/item-{item id}\0的第一个事件
项目类别位于http://localhost:2113/web/index.html#/streams/$ce-itemhttp://localhost:2113/web/index.html#/streams/$et-ItemCreated上的ItemCreated事件http://localhost:2113/web/index.html#/streams/$et-ItemChanged上的ItemChanged事件

关于c# - 有没有一种方法可以启动Windows中提供的EventStore(根本不需要使用docker)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65225097/

相关文章:

java - 是否有 Java 端口或 NEventStore 库的等效项?

cqrs - 通过事件溯源进行逻辑删除(可能包含敏感数据/GDPR)

c# - Xamarin Android 从图库获取图像数据

c# - 字段System.MulticastDelegate._invocationCount不可用C#

c# - ASP.NET 页面性能

c# - 将日期范围拆分为多个范围?

.net - 复杂的DTO结构

c# - Json.Net 意外字符 ("\") 序列化我的实体时

c# - 禁用 NIC 或阻止所有 tcp 连接

sql-server - 具有事件源的 CQRS 模式具有用于读/写的单个数据库