Created
March 24, 2014 03:57
-
-
Save jmarnold/9733886 to your computer and use it in GitHub Desktop.
Appending to streams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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