当Event Server启动之后,可以通过HTTP的Event API或者是PredictionIO的SDK的EventClient访问。

PIO默认的EventServer是HBase,当启动HBase时,请允许其30s的初始时间。

启动event server

$ pio eventserver

默认Event Server绑定到0.0.0.0,为了安全可以限制于本地

pio eventserver --ip 127.0.0.1

查看Server状态

$ curl -i -X GET http://localhost:7070

创建应用

$ pio app new MyTestApp

通过http请求event

$ curl -i -X POST http://localhost:7070/events.json?accessKey=WPgcXKd42FPQpZHVbVeMyqF4CQJUnXQmIMTHhX3ZUrSzvy1KXJjdFUrslifa9rnB \
-H "Content-Type: application/json" \
-d '{
  "event" : "my_event",
  "entityType" : "user",
  "entityId" : "uid",
  "properties" : {
    "prop1" : 1,
    "prop2" : "value2",
    "prop3" : [1, 2, 3],
    "prop4" : true,
    "prop5" : ["a", "b", "c"],
    "prop6" : 4.56
  }
  "eventTime" : "2004-12-13T21:39:45.618-07:00"
}'

一个event包含两个entity

$ curl -i -X POST http://localhost:7070/events.json?accessKey=WPgcXKd42FPQpZHVbVeMyqF4CQJUnXQmIMTHhX3ZUrSzvy1KXJjdFUrslifa9rnB \
-H "Content-Type: application/json" \
-d '{
  "event" : "my_event",
  "entityType" : "user",
  "entityId" : "uid",
  "targetEntityType" : "item",
  "targetEntityId" : "iid",
  "properties" : {
    "someProperty" : "value1",
    "anotherProperty" : "value2"
  },
  "eventTime" : "2004-12-13T21:39:45.618Z"
}'

获取event

$ curl -i -X GET http://localhost:7070/events/<your_eventId>.json?accessKey=<your_accessKey>

删除event

$ curl -i -X DELETE http://localhost:7070/events/<your_eventId>.json?accessKey=<your_accessKey>

获取所有的event

$ curl -i -X GET http://localhost:7070/events.json?accessKey=<your_accessKey>

删除所有event

$ pio app data-delete <your_app_name>

Event封装

一般Event封装

用户登录

{
  "event" : "sign-up",
  "entityType" : "user",
  "entityId" : "1"
}

用户查看商品

{
  "event" : "view",
  "entityType" : "user",
  "entityId" : "1",
  "targetEntityType" : "item",
  "targetEntityId" : "1"
}

用户评价商品,评分四星

{
  "event" : "rate",
  "entityType" : "user",
  "entityId" : "1",
  "targetEntityType" : "item",
  "targetEntityId" : "1",
  "properties" : {
    "rating" : 4
  }
}

特殊Event封装

修改用户的生日和地址信息

{
  "event" : "$set",
  "entityType" : "user",
  "entityId" : "1",
  "properties" : {
    "birthday" : "1984-10-11",
    "address" : "1234 Street, San Francisco, CA 94107"
  }
}

用户的状态因event和eventtime而不同。

批量Event

curl -i -X POST http://localhost:7070/batch/events.json?accessKey=...
-H "Content-Type: application/json" -d ‘ \
[
    {
        "event": "$create",
        "entityType": "user",
        "entityId": "uid",
        "properties": {
            ...
        }
    },
    {
        "event": "like",
        "entityType": "user",
        "entityId": "uid",
        "targetEntityType": "item",
        "targetEntityId": "iid",
        "properties": {
            ...
        }
        "eventTime": "2004-12-13T21:39:45.618-07:00"
    },
    ...
]

Channel

results matching ""

    No results matching ""