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...

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

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历