Jump to content









Photo

What should be in Context?

listener context api

  • Please log in to reply
6 replies to this topic

#1 Zambiot

Zambiot

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts
  • LocationAsia

Posted 14 May 2013 - 04:58 AM

Carriots - 

 

I've created a listener that is using "Event Data Received".  I've got an e-mail coming to me that has the context in the message body using the following code.

email.message = context;

 

 

Based on other discussions on the forum, I expected to see the fields "_t", "at", "protocol" and "id_developer" for the specific stream within the context in the listener.  What I am getting is the following (with important info replaced with xxxxx).

{session=no-session, data={xxxxxxx}, hierarchy={project={id_developer=xxxxx@Zambiot, _id=xxxxxx}, service={id_developer=xxxxxx@Zambiot, _id=xxxxxxx}, device={id_developer=xxxxxx@Zambiot, frequency_stream=2, _id=xxxxx, frequency_status=12, status=ok, checksum=null}, customer={id_developer=@Zambiot, _id=xxxxx}, group={id_developer=xxxxxxx@Zambiot, _id=xxxxxxx}}}

 

How can I get the streams details for the stream that caused the event?



#2 Zambiot

Zambiot

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts
  • LocationAsia

Posted 16 May 2013 - 06:35 AM

To add a little more fuel to my question.  It looks like if the stream ID was in the context, then the SDK could be used to lookup the stream and grab the information from it.



#3 alvaro

alvaro

    Carriots CTO

  • Administrators
  • 72 posts

Posted 18 May 2013 - 12:06 PM

Hello Zambiot.

 

Context should contain all stream content and its metadata except the apikey for security reasons. It was present in our first release but when we saw that apikey shown we decided to remove it. Metadata will include HTTP headers information like the user agent, the source IP address and other headers (specially carriots.apikey). We don't want a full privilege apikey to be seen by a read-only apikey query! 

 

For now, a new release of our stream queue processor is planned for next week including metadata (without apikey) and envelope data (at, checksum and protocol) injection into execution context and stream persistence (useful too). We hope it will help you in your project development.

 

Enjoy Carriots! 


Alvaro Everlet

Carriots CTO


#4 Zambiot

Zambiot

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts
  • LocationAsia

Posted 18 May 2013 - 11:24 PM

Thank you Alvaro.  I am looking forward to this release, as I am paused at the moment on developing until I can get the envelope data for the stream causing a listener to fire.



#5 alvaro

alvaro

    Carriots CTO

  • Administrators
  • 72 posts

Posted 21 May 2013 - 07:15 AM

Hello Zambiot.

 

The new context data is now available. You will see there are two new fields in the context: one for the envelope (context.envelope) and the other for the query metadata (context.meta).

 

When using the full context in a listener or rule script you will see something like the following.

 

 

{
 session=no-session,
 envelope=
    {
        protocol=v2,
        device=device@carriots,
        at=1369057044,
        checksum=,
        _t=str
    },
 data=
    {
        key=value
    },
 hierarchy=
    {
        project={…},
        service={…},
        device={…},
        group={…}
    },
 meta=
    {
        ve=HTTP/1.0,
        ur=/streams/,
        me=POST,
        he={
            Host=api.carriots.com,
            Content-Length=210,
            Accept-Encoding=gzip, deflate, compress,
            User-Agent=python-requests/0.14.1 CPython/2.7.4 Linux/3.8.0-21-generic,
            Content-Type=application/json,
            Connection=close,
            Accept=application/vnd.carriots.api.v2+json;q=7, text/html;q=3, */*;q=5,
            X-Scheme=https,
            X-Real-Ip=1.2.3.4
        },
        ho=api.carriots.com,
        pr=http
    }
}

 

 

 

This was a context example in a data received event. When displayed in a data persisted event you will find the key id_developer and its corresponding value in the envelope. This is the true id_developer value after stream persistence.

 

Metadata properties:

·       ve = version

·       ur = URL

·       me = method

·       he = HTTP headers

·       ho = host

·       pr = protocol

 

As usual we are working on the official documentation.

 

Enjoy Carriots!


Alvaro Everlet

Carriots CTO


#6 Zambiot

Zambiot

    Advanced Member

  • Members
  • PipPipPip
  • 94 posts
  • LocationAsia

Posted 21 May 2013 - 09:39 AM

Thank you Alvaro for the update!  I'll get back to work with coding now that this is available.  

 

Remind me again, what is the difference with Data Received and Data Persisted events?  Why not have id_developer available in both?



#7 alvaro

alvaro

    Carriots CTO

  • Administrators
  • 72 posts

Posted 21 May 2013 - 03:34 PM

Hello Zambiot.

 

Data received event is raised when the stream is received by Carriots, before storing it in the DB. Carriots hasn't calculated the id_developer yet. Data persisted event is fired after stream persistence is done, so the id_developer is calculated and the stream can be returned by a query. 

 

Hope it helps!


Alvaro Everlet

Carriots CTO






Also tagged with one or more of these keywords: listener, context, api

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users