duan3601 2019-05-03 18:43
浏览 13
已采纳

如何将架构与有效负载相关联?

For context: I am setting up a PubSub Emitter for snowplow. (For other readers PubSub is a simple queue on Google Cloud Platforms that takes in messages which are an array as input).

['data' => 'Name', 'attributes' => 'key pair values of whatever data you are sending']

The above is irrelevant except that I must create a custom Emitter class in order to achieve this goal since Google Cloud PubSub has some different connectors than the stereotypical http request/sockets/others that snowplow provides.

Actual problem:

I want to set a specific schema for each event I am sending. How do you associate the schema to each payload?

The PHP Tracker SyncEmitter (the most standard snowplow provided Emitter) doesn't allow any custom setting for the schema (as shown below)

private function getPostRequest($buffer) {
    $data = array("schema" => self::POST_REQ_SCEHMA, "data" => $buffer);
    return $data;
}

It is hardcoded in to every event tracked.

So I investigated. And read up on snowplow trackers a bit more. I am still baffled, and I know I can extend the Payload class and force my own schemas as a variable, but why is it not this way already? I am asking because I am assuming the opensource programmer did it right, and I am not understanding it correctly.

  • 写回答

1条回答 默认 最新

  • dtt5830659 2019-05-03 20:45
    关注

    I figured it out.

    The Tracker class contains trackUnstructuredEvent:

    /**
     * Tracks an unstructured event with the aforementioned metrics
     *
     * @param array $event_json - The properties of the event. Has two fields:
     *                           - A "data" field containing the event properties and
     *                           - A "schema" field identifying the schema against which the data is validated
     * @param array|null $context - Event Context
     * @param int|null $tstamp - Event Timestamp
     */
    public function trackUnstructEvent($event_json, $context = NULL, $tstamp = NULL) {
        $envelope = array("schema" => self::UNSTRUCT_EVENT_SCHEMA, "data" => $event_json);
        $ep = new Payload($tstamp);
        $ep->add("e", "ue");
        $ep->addJson($envelope, $this->encode_base64, "ue_px", "ue_pr");
        $this->track($ep, $context);
    }
    

    Which accepts the schema as input. Snowplow wants you to use the Tracker's default function and provided the above as a solution to my issue.

    But it still has a schema wrapped around the data(that contains the input schema).... More questions from my own answer...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗