c# - 尝试将流事件附加到 EventStore 会引发异常
问题描述
我目前正在开始使用EventStore,并且正在遵循入门指南。我只是卡在第一步,不知道我做错了什么......
我现在使用的版本是20.6.0。
我正在尝试使用 .NET Core 客户端将事件写入我的本地实例(它正在运行,因为我可以使用 AdminUI 添加事件)。但我得到一个例外,比如One or more errors occurred. (Connection 'ES-41230054-2026-4cdb-b2bb-a35824779863' was closed.)'
.
在尝试修复它一段时间后,我去了.Net 客户端指南并粘贴了完全相同的代码:
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
在输出中注意到了这一点:
如果我这样做telnet 127.0.0.1 1113
,它似乎无法连接,但我没有找到问题所在。任何想法?
解决方案
我有完全相同的问题@devcrp
- 当您启动服务器时,带有“接口”的图像直接将我指向丢失的标志。
解决方案(对于 20.6.0 > )是在启动事件存储时添加此标志
--enable-external-tcp
我在管理 UI 中禁用“流浏览器”时遇到了类似的问题,它需要
--enable-atom-pub-over-http
我还有一些其他问题,比如不知道访问管理 UI 需要 https,http 在文档中说明并且不起作用(在 20.6.0 中也是新的)以及如何让配置文件工作(也是由于文档中的过时标志 ExtSecureTcpPort 以及缺少有关 TrustedRootCertificatesPath 的信息)
- 这里有一些关于使用 TrustedRootCertificatesPath 工作的 config.yaml 的信息https://gist.github.com/JimiSweden/f8916a94bd3dab1ff07c940b9169c946
如果您在“接口”之后查看控制台中声明“弃用警告”的行,则会提示为什么需要启用 atom-pub-over-http 和 external-tcp
这是我的控制台输出,启用了 external-tcp 和 atom-pub-over-http
您在这里看到的与防火墙等无关,它只是事件存储的输出。
[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.
这是我的工作启动命令 (在一个名为 '.\eventstore start command.ps1' 的文件中,以便更简单地运行服务器)
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
推荐阅读
- mainframe - 包括 cond= 字符串搜索和通配符?
- javascript - 如何使用javascript选择没有类名或ID的div元素内的选择或输入元素?
- mysql - 这是 3NF 中一个好的数据库设计吗?
- mysql - 如何找到RDS中所有不支持和不可修改的参数?
- reactjs - 为什么我无法读取未定义的属性“地图”
- asp.net - 身份验证不会对挑战进行回程,仅显示当前用户个人资料页面
- node.js - 如何防止自定义 markdown-it 插件将特殊字符转义为 HTML 实体?
- php - Laravel 8 @yeild @section 没有传递数据空白页
- java - 如何在 Jpa 标准中移植 postgresql 时区语句
- python - 有没有更好的方法来获取创建的对象?