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

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

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?