gpt4 book ai didi

c# - 尝试将流事件附加到 EventStore 会引发异常

转载 作者:行者123 更新时间:2023-12-04 00:18:36 26 4
gpt4 key购买 nike

我目前正在开始使用 EventStore我正在关注 Getting Started指导。我只是卡在第一步,不知道我做错了什么......

我现在使用的版本是 20.6.0 .

我正在尝试使用 .NET Core 客户端将事件写入我的本地实例(它正在运行,因为我可以使用 AdminUI 添加事件)。但我得到一个异常(exception),如 One or more errors occurred. (Connection 'ES-41230054-2026-4cdb-b2bb-a35824779863' was closed.)' .

在尝试修复它一段时间后,我去了 .Net Client guide并粘贴完全相同的代码:

        public static void Main()
{
var conn = EventStoreConnection.Create(new Uri("tcp://admin:changeit@localhost:1113"));
conn.ConnectAsync().Wait();

var data = Encoding.UTF8.GetBytes("{\"a\":\"2\"}");
var metadata = Encoding.UTF8.GetBytes("{}");
var evt = new EventData(Guid.NewGuid(), "testEvent", true, data, metadata);

conn.AppendToStreamAsync("test-stream", ExpectedVersion.Any, evt).Wait();

var streamEvents = conn.ReadStreamEventsForwardAsync("test-stream", 0, 1, false).Result;
var returnedEvent = streamEvents.Events[0].Event;

Console.WriteLine("Read event with data: {0}, metadata: {1}",
Encoding.UTF8.GetString(returnedEvent.Data),
Encoding.UTF8.GetString(returnedEvent.Metadata));
}
}

但是当我到达这一行时,也会引发同样的异常:
conn.AppendToStreamAsync("test-stream", ExpectedVersion.Any, evt).Wait();

我在创建连接时尝试了不同的方法,但到目前为止都没有。

我想知道我是否遗漏了一些配置......如果有人遇到过这个问题并能为我提供一些启示,我将非常感激。

添加更多信息

激活日志记录后,我看到了以下内容:
  • 尝试附加事件时,我得到以下输出:
  • [01,07:28:46.528,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': enqueueing message EventStore.ClientAPI.Internal.StartConnectionMessage..
    [04,07:28:46.545,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': StartConnection.
    [04,07:28:46.546,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': DiscoverEndPoint.
    [04,07:28:46.549,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': enqueueing message EventStore.ClientAPI.Internal.EstablishTcpConnectionMessage..
    [06,07:28:46.561,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': EstablishTcpConnection to [127.0.0.1:1113].
    [05,07:28:46.582,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': enqueueing message EventStore.ClientAPI.Internal.StartOperationMessage..
    [06,07:28:46.642,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': StartOperation enqueue AppendToStreamOperation, Stream: newstream, ExpectedVersion: -2, 10, 00:00:07..
    [06,07:28:46.643,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': EnqueueOperation WAITING for Operation AppendToStreamOperation (a301f19c-bb92-4c53-a193-3a81582a49db): Stream: newstream, ExpectedVersion: -2, retry count: 0, created: 07:28:46.642, last updated: 07:28:46.642..
    [08,07:28:48.702,DEBUG] TcpPackageConnection: connection to [127.0.0.1:1113, L, {69f92d44-54ab-4643-b540-23f89b796fcf}] failed. Error: ConnectionRefused.
    [08,07:28:48.703,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': enqueueing message EventStore.ClientAPI.Internal.TcpConnectionClosedMessage..
    [08,07:28:48.704,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': TCP connection to [127.0.0.1:1113, L, {69f92d44-54ab-4643-b540-23f89b796fcf}] closed..
    [06,07:28:48.924,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': TimerTick checking reconnection....
    [06,07:28:49.213,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': ExecuteOperation package WriteEvents, a301f19c-bb92-4c53-a193-3a81582a49db, Operation AppendToStreamOperation (a301f19c-bb92-4c53-a193-3a81582a49db): Stream: newstream, ExpectedVersion: -2, retry count: 0, created: 07:28:46.642, last updated: 07:28:48.935..
    [06,07:28:49.229,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': DiscoverEndPoint.
    [06,07:28:49.230,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': enqueueing message EventStore.ClientAPI.Internal.EstablishTcpConnectionMessage..
    [04,07:28:49.231,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': EstablishTcpConnection to [127.0.0.1:1113].

    所以这似乎是说问题在于端口未打开,我尝试完全禁用防火墙但没有运气。
  • 同样当我执行命令 EventStore.ClusterNode.exe --db ./db --log ./logs --dev我在输出中注意到了这一点:

  • enter image description here

    如果我这样做 telnet 127.0.0.1 1113它似乎无法连接,但我没有找到问题所在。任何的想法?

    最佳答案

    我有完全相同的问题@devcrp

  • 当您启动服务器时,带有“接口(interface)”的图像直接将我指向丢失的标志。

  • 解决方案(对于 20.6.0 > )是在启动事件存储时添加此标志
    --enable-external-tcp
    我在管理 UI 中禁用“流浏览器”时遇到了类似的问题,它需要
    --enable-atom-pub-over-http 
    我还有其他一些问题🤠
    就像不知道访问管理 UI 需要 https 一样,http 已在文档中说明并且不起作用(在 20.6.0 中也是新的)以及如何使配置文件工作(也是由于过时的标志,ExtSecureTcpPort,在文档中,并且缺少有关 TrustedRootCertificatesPath 的信息)
  • 这里有一些关于使用 config.yaml 和 TrustedRootCertificatesPath https://gist.github.com/JimiSweden/f8916a94bd3dab1ff07c940b9169c946 的信息

  • 如果您在“接口(interface)”之后查看控制台中声明“弃用警告”的行,就会提示为什么需要启用 atom-pub-over-http 和 external-tcp

    Here is my console output with external-tcp and atom-pub-over-http enabled

    what you see here has nothing to do with firewalls etc, it is solely the output from event store.

    [28224, 1,22:27:51.677,INF]
    INTERFACES
    External TCP (Protobuf)
    Enabled : True
    Port : 1113
    HTTP (AtomPub)
    Enabled : True
    Port : 2113

    [28224, 1,22:27:51.678,WRN]
    DEPRECATION WARNING: AtomPub over HTTP Interface has been deprecated as of version 20.02. It is recommended to use gRPC instead.

    [28224, 1,22:27:51.678,WRN]
    DEPRECATION WARNING: The Legacy TCP Client Interface has been deprecated as of version 20.02. The External TCP Interface can be re-enabled with the 'EnableExternalTCP' option. It is recommended to use gRPC instead.

    This is my working start command(in a file called '.\eventstore start command.ps1' to make it simpler to run the server)


    screen capture of powershell file as start command
    EventStore.ClusterNode.exe --db ./db --log ./logs --config=config.yaml --enable-atom-pub-over-http --enable-external-tcp --run-projections=all --start-standard-projections=true

    关于c# - 尝试将流事件附加到 EventStore 会引发异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62341899/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com