Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Appending to streams
class Program
{
static void Main(string[] args)
{
var settings = ConnectionSettings.Create()
.EnableVerboseLogging()
.UseCustomLogger(ClientApiLoggerBridge.Default)
.LimitReconnectionsTo(1)
.WithConnectionTimeoutOf(TimeSpan.FromSeconds(10))
.SetReconnectionDelayTo(TimeSpan.FromMilliseconds(0))
.FailOnNoServerResponse();
var store = EventStoreConnection.Create(settings, new IPEndPoint(IPAddress.Loopback, 2113));
store.Connect();
try
{
store.AppendToStream("mystream", ExpectedVersion.NoStream, TestEvent.NewTestEvent());
Console.WriteLine("Wrote *something*");
}
catch (Exception exception)
{
Console.WriteLine(exception.InnerException.Message);
}
store.Close();
Console.ReadLine();
}
}
public class TestEvent
{
public static EventData NewTestEvent(string data = null, string metadata = null)
{
return NewTestEvent(Guid.NewGuid(), data, metadata);
}
public static EventData NewTestEvent(Guid eventId, string data = null, string metadata = null)
{
var encodedData = Helper.UTF8NoBom.GetBytes(data ?? eventId.ToString());
var encodedMetadata = Helper.UTF8NoBom.GetBytes(metadata ?? "metadata");
return new EventData(eventId, "TestEvent", false, encodedData, encodedMetadata);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.