Using projections with EventStore.ClientAPI.Embedded

Hi,

We’ve just been trying to use the EventStore.ClientAPI.Embedded in a test and ran into problems trying to enable projections. This is the code we have taken from here https://github.com/yreynhout/AggregateSource/blob/d5be94fb805f44838121759bb86b4cb41a1ac85f/src/EventStore/AggregateSource.EventStore.IntegratedTests/Framework/EmbeddedEventStore.cs

public static void Start()

{

var ipAddress = IPAddress.Parse(“127.0.0.1”);

var node = EmbeddedVNodeBuilder.

AsSingleNode().

RunProjections(ProjectionsMode.All).

WithInternalHttpOn(new IPEndPoint(ipAddress, 2219)).

WithExternalHttpOn(new IPEndPoint(ipAddress, 2220)).

WithInternalTcpOn(new IPEndPoint(ipAddress, 1219)).

WithExternalTcpOn(new IPEndPoint(ipAddress, 1220)).

RunInMemory().

Build();

node.Start();

var tcs = new TaskCompletionSource();

node.NodeStatusChanged += (sender, args) =>

{

if (args.NewVNodeState == VNodeState.Master)

tcs.SetResult(null);

};

tcs.Task.Wait();

Node = node;

Credentials = new UserCredentials(“admin”, “changeit”);

var connection = EmbeddedEventStoreConnection.Create(Node);

connection.ConnectAsync().Wait();

Connection = connection;

EnableProjection("$by_event_type", new IPEndPoint(ipAddress, 2220));

EnableProjection("$by_category", new IPEndPoint(ipAddress, 2220));

}

private static void EnableProjection(string projectionName, IPEndPoint httpEndpoint)

{

var webClient = new WebClient() { Credentials = new NetworkCredential(“admin”, “changeit”) };

var url = string.Format(“http://{0}:{1}/projection/{2}/command/enable”, httpEndpoint.Address, httpEndpoint.Port,

projectionName);

var uploadString = webClient.UploadString(url, “POST”, “”);

}

``

``

We also cannot browse to the instance (i.e. http://127.0.0.1:2220)

Is it possible to use projections with the embedded version? If so, what are we doing wrong? :slight_smile:

Thanks

Tom

Are you running on windows? Might be urlacls. Try running visual studio as administrator

Yeah running on windows, already running visual studio as administrator. I’ll try and look into it more tonight. Cheers

It is definitely possible, I’ve done it.

We have these extra lines before vNode.Start():

      vNode.ExternalHttpService.SetupController(new UsersWebController(vNode.MainQueue));
      vNode.ExternalHttpService.SetupController(new ClusterWebUiController(vNode.MainQueue,
        new[] { NodeSubsystems.Projections }));

Thanks, I will give this a try

I had this issue.

private const string ExternalHttpAddress = “http://localhost:3030/”;

var clusterVNode = EmbeddedVNodeBuilder.AsSingleNode()

.RunInMemory()

.RunProjections(ProjectionsMode.All)

.OnDefaultEndpoints()

.AddExternalHttpPrefix(ExternalHttpAddress)

.Build();

The prefixes are ACL’ed, solved the issue for me. Also note, the WEB UI isnt bundled so you have to run that from disk.