Issue when trying to replicate the Cachup subscription example

Hi All,

I’m trying to replicate the catch up subscriptions example from:

http://geteventstore.com/blog/20130707/catch-up-subscriptions-with-the-event-store/index.html

I realise things may have changed with ES 3.0.1.

I’m starting the event store as follows:

EventStore.ClusterNode –db=data –stats-period-sec 2

This is successfully starting and giving me events on the $stats stream.

I then have the following code in a standard console application:

using
EventStore.ClientAPI;

using
System;

using
System.Net;

using
System.Threading.Tasks;

using
System.IO;

using
System.Reflection;

namespace
EventStoreTest

{

class
Program

{

static
void Main(string []
args)

{

IEventStoreConnection connection =
null;

using (connection =EventStoreConnection.Create(new
IPEndPoint(IPAddress .Loopback,
1113)))

{

connection.ConnectAsync();

EventStoreCatchUpSubscription sub = connection.SubscribeToStreamFrom("$stats-127.0.0.1:2113",
StreamCheckpoint.StreamStart,
true, EventAccepted, GoneLive, SubscriptionDropped);

            Console.ReadLine();

}

}

private
static
void SubscriptionDropped(EventStoreCatchUpSubscription
arg1, SubscriptionDropReason arg2,
Exception arg3)

{

Console.WriteLine( “subscription
dropped.”);

}

private
static
void GoneLive(EventStoreCatchUpSubscription
obj)

{

Console.WriteLine( “Gone
live”);

}

private
static
void EventAccepted(EventStoreCatchUpSubscription
arg1, ResolvedEvent arg2)

{

Console.WriteLine( “Event
accepted.”);

}

}

}

The SubscriptionDropped method always gets called, but neither the goneLive or EventAccepted ever do.

It seems from the acception that the connection is being closed and that I’m getting a message that read access is denied for the $stats stream.

The exception stack trace is below:

System.AggregateException was unhandled

HResult=-2146233088

Message=One or more errors occurred.

Source=EventStoreTest

StackTrace:

at EventStoreTest.Program.SubscriptionDropped(EventStoreCatchUpSubscription arg1, SubscriptionDropReason arg2, Exception arg3) in z:\work\EventStoreTest\EventStoreTest\Program.cs:line 32

at EventStore.ClientAPI.EventStoreCatchUpSubscription.DropSubscription(SubscriptionDropReason reason, Exception error)

at EventStore.ClientAPI.EventStoreCatchUpSubscription.b__0(Object _)

at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()

at System.Threading.ThreadPoolWorkQueue.Dispatch()

at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

InnerException: EventStore.ClientAPI.Exceptions.AccessDeniedException

HResult=-2146233088

Message=Read access denied for stream ‘$stats-127.0.0.1:2113’.

InnerException:

I was under the impression that the .net client connected as an admin user hence could read all streams.

Any help appreciated.

Kind regards

Sean.

You have to tell the connection what user to use

https://github.com/EventStore/EventStore/blob/dev/src/EventStore.ClientAPI/IEventStoreConnection.cs#L257

It takes a credentials object.

Cheers,

Greg

Hi,

Thanks that works.
Is there a way in the .net api to create/delete users?
Kind regards
Sean.

Its a RESTful api would be useful if we added methods into client
though will drop up a issue on that

protected override void SubscribeCore(IHttpService service)
{
RegisterUrlBased(service, "/users/", HttpMethod.Get, GetUsers);
RegisterUrlBased(service, "/users/{login}", HttpMethod.Get, GetUser);
RegisterUrlBased(service, "/users/$current", HttpMethod.Get, GetCurrentUser);
Register(service, "/users/", HttpMethod.Post, PostUser, DefaultCodecs,
DefaultCodecs);
Register(service, "/users/{login}", HttpMethod.Put, PutUser,
DefaultCodecs, DefaultCodecs);
RegisterUrlBased(service, "/users/{login}", HttpMethod.Delete, DeleteUser);
RegisterUrlBased(service, "/users/{login}/command/enable",
HttpMethod.Post, PostCommandEnable);
RegisterUrlBased(service, "/users/{login}/command/disable",
HttpMethod.Post, PostCommandDisable);
Register(service, "/users/{login}/command/reset-password",
HttpMethod.Post, PostCommandResetPassword, DefaultCodecs,
DefaultCodecs);
Register(service, "/users/{login}/command/change-password",
HttpMethod.Post, PostCommandChangePassword, DefaultCodecs,
DefaultCodecs);
}

For data:

private class PostUserData
{
public string LoginName { get; set; }
public string FullName { get; set; }
public string[] Groups { get; set; }
public string Password { get; set; }
}
private class PutUserData
{
public string FullName { get; set; }
public string[] Groups { get; set; }
}
private class ResetPasswordData
{
public string NewPassword { get; set; }
}
private class ChangePasswordData
{
public string CurrentPassword { get; set; }
public string NewPassword { get; set; }
}

This is actually a good first commit for anyone wanting to try their
hands at some dev work

https://github.com/EventStore/EventStore/issues/293

Hi,

I'm happy to take this, if someone wants to assign me to it.
My GitHub yuser name is SeanFarrow.
Kind regards
Sean.

The $all stream and I believe any stream prefixed with $ is only readable by the ‘admin’ user by default.