Get metadata + data in one request (from alternate URI(

Hi guys, I need help getting metadata please - given an event retrieved by a HttpWebRequest from the Atom feed (with a URI = http://127.0.0.1:2113/web/index.html#/streams/customer-95151697/1)

Is there any way to get the Metadata from the post?

Via the web browser I can see:

Data

{

“NewAddress”: “new street 123”,

“OccurredOn”: “2015-07-12T19:29:46.6842154Z”,

“EventCorrelationId”: “939d676b-d620-4c36-8337-f71eb9422938”

}

Metadata

{

“CommitId”: “a53ff880-5d3b-444f-83d8-c3fdd473a6a7”,

“AggregateClrTypeName”: “Test.Domain.Model.Customer.Customer, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”,

“EventClrTypeName”: “Test.Domain.Model.Customer.CustomerChanedAddress, Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”

}

But when I read via:

void ProcessItems(IEnumerable items)

{

Console.ForegroundColor = ConsoleColor.DarkRed;

foreach (var item in items)

{

Console.WriteLine("Dispatching event " + item.Links.Alternate());

using (var response = BuildRequest(item, “application/json”).GetResponse())

{

// dispatch to bus

}

}

}

HttpWebRequest BuildRequest(Uri uri, string acceptHeaderType = “application/atom+xml”)

{

var request = (HttpWebRequest)WebRequest.Create(uri);

request.Credentials = this.credentials;

request.Accept = acceptHeaderType;

return request;

}

There is no metadata, only the data component. Please note when looping through the SyndicationItems the only links I have are ‘edit’ and ‘alternate’.

Ideally I would like to get the event content and metadata in one request, is that possible?

On the main feed try embed=content

Sorry Greg, on the stream http://127.0.0.1:2113/streams/customer-12683118?embed=body I get (which seems to list all events):

{

“title”: “Event stream ‘customer-12683118’”,

“id”: “http://127.0.0.1:2113/streams/customer-12683118”,

“updated”: “2015-07-12T19:29:47.7623411Z”,

“streamId”: “customer-12683118”,

“author”: {

“name”: “EventStore”

},

“headOfStream”: true,

“selfUrl”: “http://127.0.0.1:2113/streams/customer-12683118”,

“eTag”: “1;-2060438500”,

“links”: [

{

“uri”: “http://127.0.0.1:2113/streams/customer-12683118”,

“relation”: “self”

},

{

“uri”: “http://127.0.0.1:2113/streams/customer-12683118/head/backward/20”,

“relation”: “first”

},

{

“uri”: “http://127.0.0.1:2113/streams/customer-12683118/2/forward/20”,

“relation”: “previous”

},

{

“uri”: “http://127.0.0.1:2113/streams/customer-12683118/metadata”,

“relation”: “metadata”

}

],

“entries”: [

{

“eventId”: “c2c55854-0f3d-4bdf-ab89-a87a16b6352f”,

“eventType”: “CustomerChanedAddress”,

“eventNumber”: 1,

“data”: “{“NewAddress”:“new street 123”,“OccurredOn”:“2015-07-12T19:29:47.7623411Z”,“EventCorrelationId”:“dde5d74e-ad78-489d-b458-8483db808532”}”,

“streamId”: “customer-12683118”,

“isJson”: true,

“isMetaData”: false,

“isLinkMetaData”: false,

“positionEventNumber”: 1,

“positionStreamId”: “customer-12683118”,

“title”: “1@customer-12683118”,

“id”: “http://127.0.0.1:2113/streams/customer-12683118/1”,

“updated”: “2015-07-12T19:29:47.7623411Z”,

“author”: {

“name”: “EventStore”

},

“summary”: “CustomerChanedAddress”,

“links”: [

{

“uri”: “http://127.0.0.1:2113/streams/customer-12683118/1”,

“relation”: “edit”

},

{

“uri”: “http://127.0.0.1:2113/streams/customer-12683118/1”,

“relation”: “alternate”

}

]

},

{

“eventId”: “9101a738-2b5b-4e59-96ab-beca689e8fe1”,

“eventType”: “CustomerCreated”,

“eventNumber”: 0,

“data”: “{“Name”:“chris”,“Address”:“abc street”,“PersonId”:{“SocialSecurityNumber”:12683118},“OccurredOn”:“2015-07-12T19:29:47.7623411Z”,“EventCorrelationId”:“0c36087c-40dd-4b6d-bd07-6782882e1c19”}”,

“streamId”: “customer-12683118”,

“isJson”: true,

“isMetaData”: false,

“isLinkMetaData”: false,

“positionEventNumber”: 0,

“positionStreamId”: “customer-12683118”,

“title”: “0@customer-12683118”,

“id”: “http://127.0.0.1:2113/streams/customer-12683118/0”,

“updated”: “2015-07-12T19:29:47.7623411Z”,

“author”: {

“name”: “EventStore”

},

“summary”: “CustomerCreated”,

“links”: [

{

“uri”: “http://127.0.0.1:2113/streams/customer-12683118/0”,

“relation”: “edit”

},

{

“uri”: “http://127.0.0.1:2113/streams/customer-12683118/0”,

“relation”: “alternate”

}

]

}

]

}

And http://127.0.0.1:2113/streams/$all?embed=body doesnt return any different… if I could get the same content (data+metadata) as per the attached for each SyndicateItem it would be amazing.

Hate the newb question but pointers much appreciated.

event-store.png

Try this

curl -v -i "http://127.0.0.1:2113/streams/%24stats-127.0.0.1:2113?embed=content"
-u admin:changeit -H "Accept: application/json"

content not body my bad.

Greg

Thanks Greg, on the root of the stream that works.

I am using a poler based on the getting started code to go through the syndication items (starting from last known position): http://pastebin.com/ceaK0xGp

It dispatches the events:

Dispatching event http://127.0.0.1:2113/streams/customer-71464221/0

Dispatching event http://127.0.0.1:2113/streams/customer-71464221/1

Dispatching event http://127.0.0.1:2113/streams/customer-67981065/0

Dispatching event http://127.0.0.1:2113/streams/customer-67981065/1

Dispatching event http://127.0.0.1:2113/streams/customer-12307621/0

Dispatching event http://127.0.0.1:2113/streams/customer-12307621/1

Dispatching event http://127.0.0.1:2113/streams/customer-72879842/0

Dispatching event http://127.0.0.1:2113/streams/customer-72879842/1

Dispatching event http://127.0.0.1:2113/streams/customer-69396686/0

Dispatching event http://127.0.0.1:2113/streams/customer-69396686/1

Dispatching event http://127.0.0.1:2113/streams/customer-65913530/0

Dispatching event http://127.0.0.1:2113/streams/customer-65913530/1

It would be great if there was a specific metadata query that I could call for the specific single event: http://127.0.0.1:2113/streams/customer-65913530/1?metadata.

If I call http://127.0.0.1:2113/streams/customer-20516703?embed=content the reply could be very long if lots entries in the stream.

Is getting metadata for one event not made easy with the system architecture (which everything being immutable is amazing btw)?

Just trying to avoid writing more code for the sync class :slight_smile:

C:\Users\csmorley\Downloads>curl -v -i “http://127.0.0.1:2113/streams/customer-20516703?embed=content” -u admin:changeit

-H “Accept: application/json”

  • Trying 127.0.0.1…

  • Connected to 127.0.0.1 (127.0.0.1) port 2113 (#0)

  • Server auth using Basic with user ‘admin’

GET /streams/customer-20516703?embed=content HTTP/1.1

Host: 127.0.0.1:2113

Authorization: Basic YWRtaW46Y2hhbmdlaXQ=

User-Agent: curl/7.43.0

Accept: application/json

< HTTP/1.1 200 OK

HTTP/1.1 200 OK

< Cache-Control: max-age=0, no-cache, must-revalidate

Cache-Control: max-age=0, no-cache, must-revalidate

< Content-Length: 3590

Content-Length: 3590

< Content-Type: application/json; charset=utf-8

Content-Type: application/json; charset=utf-8

< ETag: “1;1391431453”

ETag: “1;1391431453”

< Vary: Accept

Vary: Accept

< Server: Microsoft-HTTPAPI/2.0

Server: Microsoft-HTTPAPI/2.0

< Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS

Access-Control-Allow-Methods: POST, DELETE, GET, OPTIONS

< Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVers

ion, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTo, ES-ExpectedVersion

Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVersio

n, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTo, ES-ExpectedVersion

< Access-Control-Allow-Origin: *

Access-Control-Allow-Origin: *

< Access-Control-Expose-Headers: Location, ES-Position

Access-Control-Expose-Headers: Location, ES-Position

< Date: Mon, 13 Jul 2015 17:04:35 GMT

<

{

“title”: “Event stream ‘customer-20516703’”,

“id”: “http://127.0.0.1:2113/streams/customer-20516703”,

“updated”: “2015-07-13T17:03:40.7486008Z”,

“streamId”: “customer-20516703”,

“author”: {

“name”: “EventStore”

},

“headOfStream”: true,

“selfUrl”: “http://127.0.0.1:2113/streams/customer-20516703”,

“eTag”: “1;-2060438500”,

“links”: [

{

“uri”: “http://127.0.0.1:2113/streams/customer-20516703”,

“relation”: “self”

},

{

“uri”: “http://127.0.0.1:2113/streams/customer-20516703/head/backward/20”,

“relation”: “first”

},

{

“uri”: “http://127.0.0.1:2113/streams/customer-20516703/2/forward/20”,

“relation”: “previous”

},

{

“uri”: “http://127.0.0.1:2113/streams/customer-20516703/metadata”,

“relation”: “metadata”

}

],

“entries”: [

{

“title”: “1@customer-20516703”,

“id”: “http://127.0.0.1:2113/streams/customer-20516703/1”,

“updated”: “2015-07-13T17:03:40.7486008Z”,

“author”: {

“name”: “EventStore”

},

“summary”: “CustomerChanedAddress”,

“content”: {

“eventStreamId”: “customer-20516703”,

“eventNumber”: 1,

“eventType”: “CustomerChanedAddress”,

“data”: {

“NewAddress”: “new street 123”,

“OccurredOn”: “2015-07-13T17:03:40.7446016Z”,

“EventCorrelationId”: “54d9e71f-25f5-4303-a503-fbe78ea5cf45”

},

“metadata”: {

“CommitId”: “85d0d365-5a4b-465e-9755-aabdc8f65dd1”,

“AggregateClrTypeName”: "ProjectMaster.Domain.Model.Customer.Customer, ProjectMaster, Version=1.0.0.0, Culture

=neutral, PublicKeyToken=null",

“EventClrTypeName”: "ProjectMaster.Domain.Model.Customer.CustomerChanedAddress, ProjectMaster, Version=1.0.0.0

, Culture=neutral, PublicKeyToken=null"

}

},

“links”: [

{

“uri”: “http://127.0.0.1:2113/streams/customer-20516703/1”,

“relation”: “edit”

},

{

“uri”: “http://127.0.0.1:2113/streams/customer-20516703/1”,

“relation”: “alternate”

}

]

},

{

“title”: “0@customer-20516703”,

“id”: “http://127.0.0.1:2113/streams/customer-20516703/0”,

“updated”: “2015-07-13T17:03:40.7486008Z”,

“author”: {

“name”: “EventStore”

},

“summary”: “CustomerCreated”,

“content”: {

“eventStreamId”: “customer-20516703”,

“eventNumber”: 0,

“eventType”: “CustomerCreated”,

“data”: {

“Name”: “chris”,

“Address”: “abc street”,

“PersonId”: {

“SocialSecurityNumber”: 20516703

},

“OccurredOn”: “2015-07-13T17:03:40.7446016Z”,

“EventCorrelationId”: “9282e129-7c33-45cd-afba-b4a115f079f9”

},

“metadata”: {

“CommitId”: “85d0d365-5a4b-465e-9755-aabdc8f65dd1”,

“AggregateClrTypeName”: "ProjectMaster.Domain.Model.Customer.Customer, ProjectMaster, Version=1.0.0.0, Culture

=neutral, PublicKeyToken=null",

“EventClrTypeName”: "ProjectMaster.Domain.Model.Customer.CustomerCreated, ProjectMaster, Version=1.0.0.0, Cult

ure=neutral, PublicKeyToken=null"

}

},

“links”: [

{

“uri”: “http://127.0.0.1:2113/streams/customer-20516703/0”,

“relation”: “edit”

},

{

“uri”: “http://127.0.0.1:2113/streams/customer-20516703/0”,

“relation”: “alternate”

}

]

}

]

}* Connection #0 to host 127.0.0.1 left intact

I'm pretty sure without testing that you can do it on individual event
as well but need to test it.

Sorry should have said I had tried already and no dice

C:\Users\csmorley\Downloads>curl -v -i “http://127.0.0.1:2113/streams/customer-20516703/1?embed=content” -u admin:change

it -H “Accept: application/json”

  • Trying 127.0.0.1…

  • Connected to 127.0.0.1 (127.0.0.1) port 2113 (#0)

  • Server auth using Basic with user ‘admin’

GET /streams/customer-20516703/1?embed=content HTTP/1.1

Host: 127.0.0.1:2113

Authorization: Basic YWRtaW46Y2hhbmdlaXQ=

User-Agent: curl/7.43.0

Accept: application/json

< HTTP/1.1 200 OK

HTTP/1.1 200 OK

< Cache-Control: max-age=31536000, public

Cache-Control: max-age=31536000, public

< Content-Length: 152

Content-Length: 152

< Content-Type: application/json; charset=utf-8

Content-Type: application/json; charset=utf-8

< Vary: Accept

Vary: Accept

< Server: Microsoft-HTTPAPI/2.0

Server: Microsoft-HTTPAPI/2.0

< Access-Control-Allow-Methods: GET, OPTIONS

Access-Control-Allow-Methods: GET, OPTIONS

< Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVers

ion, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTo, ES-ExpectedVersion

Access-Control-Allow-Headers: Content-Type, X-Requested-With, X-PINGOTHER, Authorization, ES-LongPoll, ES-ExpectedVersio

n, ES-EventId, ES-EventType, ES-RequiresMaster, ES-HardDelete, ES-ResolveLinkTo, ES-ExpectedVersion

< Access-Control-Allow-Origin: *

Access-Control-Allow-Origin: *

< Access-Control-Expose-Headers: Location, ES-Position

Access-Control-Expose-Headers: Location, ES-Position

< Date: Mon, 13 Jul 2015 17:22:57 GMT

<

{

“NewAddress”: “new street 123”,

“OccurredOn”: “2015-07-13T17:03:40.7446016Z”,

“EventCorrelationId”: “54d9e71f-25f5-4303-a503-fbe78ea5cf45”

}* Connection #0 to host 127.0.0.1 left intact

Right now you have to use embed=pretty or higher IIRC, this commit fixes it and will be in v3.1.0

playing I seem to remember there is a way ...

if not I will add one.

Here you go

curl -v -i "http://127.0.0.1:2113/streams/%24stats-127.0.0.1:2113/0?embed=content"
-u admin:changeit -H "Accept: application/vnd.eventstore.event+json"

Adding issue to docs.

https://github.com/EventStore/docs.geteventstore.com/issues/127

Cheers,

Greg

btw embed=content not needed (was just playing with it)