我在玩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-item
在http://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/