Simple publish with the .Net API

Am I being an idiot here? Can connect but publising event fails. Eventstore does not seems to print anything about something failing.

module test.Main

open System
open System.Net
open System.Text
open EventStore.ClientAPI

[]
let main args =
let credentials = new IPEndPoint(IPAddress.Loopback, 2113)
let connection = EventStoreConnection.Create(credentials)
let startTask = connection.ConnectAsync()
let result = Async.AwaitIAsyncResult startTask |> Async.RunSynchronously
if result = true then
let message1 = “”"{ “hello”: “world” }"""
let data = Encoding.UTF8.GetBytes(message1)
let events = [| new EventData((Guid.NewGuid()), “first.event”, true, data, [||]) |]
let task = Async.AwaitTask (connection.AppendToStreamAsync(“TestStream”, 1, events))
Async.RunSynchronously task |> ignore

0

The result is this:

Stopped due to error

System.AggregateException: One or more errors occured —> EventStore.ClientAPI.Exceptions.RetriesLimitReachedException: Item Operation AppendToStreamOperation ({ee79b5e5-1e95-4225-9892-ee099df21b22}): Stream: TestStream, ExpectedVersion: 1, retry count: 10, created: 09:06:26.325, last updated: 09:06:38.126 reached retries limit : 10
— End of inner exception stack trace —
at Microsoft.FSharp.Control.AsyncBuilderImpl.commit[WriteResult] (Microsoft.FSharp.Control.Result1 res) [0x00000] in <filename unknown>:0 at Microsoft.FSharp.Control.CancellationTokenOps.RunSynchronously[WriteResult] (CancellationToken token, Microsoft.FSharp.Control.FSharpAsync1 computation, Microsoft.FSharp.Core.FSharpOption1 timeout) [0x00000] in <filename unknown>:0 at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[WriteResult] (Microsoft.FSharp.Control.FSharpAsync1 computation, Microsoft.FSharp.Core.FSharpOption1 timeout, Microsoft.FSharp.Core.FSharpOption1 cancellationToken) [0x00000] in :0
at <StartupCode$FSI_0030>.$FSI_0030.main@ () [0x00000] in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0
–> (Inner exception 0) EventStore.ClientAPI.Exceptions.RetriesLimitReachedException: Item Operation AppendToStreamOperation ({ee79b5e5-1e95-4225-9892-ee099df21b22}): Stream: TestStream, ExpectedVersion: 1, retry count: 10, created: 09:06:26.325, last updated: 09:06:38.126 reached retries limit : 10

Stopped due to error

Hey Svien,

Couple of small problems. You want to use the TCP port which is 1113. 2113 is the http port.

Also I think you want -1 for the expected version of the first event. There is an enum to help you out here.

module test.Main

open System

open System.Net

open System.Text

open EventStore.ClientAPI

[]

let main args =

let credentials = new IPEndPoint(IPAddress.Loopback, 1113)

let connection = EventStoreConnection.Create(credentials)

let startTask = connection.ConnectAsync()

let result = Async.AwaitIAsyncResult startTask |> Async.RunSynchronously

if result = true then

let message1 = “”"{ “hello”: “world” }"""

let data = Encoding.UTF8.GetBytes(message1)

let events = [| new EventData((Guid.NewGuid()), “first.event”, true, data, [||]) |]

let task = Async.AwaitTask (connection.AppendToStreamAsync(“TestStream”, ExpectedVersion.EmptyStream , events))

Async.RunSynchronously task |> ignore

0

cheers

Andrew

Thanks! So was am an idiot then :slight_smile: Good thing I asked this time before pulling out the bucket of chicken blood.

-Svein Arne