Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Created March 24, 2014 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmarnold/9733886 to your computer and use it in GitHub Desktop.
Save jmarnold/9733886 to your computer and use it in GitHub Desktop.
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