【问题标题】:How do you associate a schema with a payload?您如何将架构与有效负载相关联?
【发布时间】:2019-05-03 18:43:27
【问题描述】:

对于上下文: 我正在为扫雪机设置一个 PubSub 发射器。 (对于其他读者,PubSub 是谷歌云平台上的一个简单队列,它接收作为输入的数组消息)。

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

除了我必须创建一个自定义的 Emitter 类以实现此目标之外,上述内容无关紧要,因为 Google Cloud PubSub 与扫雪机提供的典型 http 请求/套接字/其他连接器有一些不同的连接器。

实际问题:

我想为我发送的每个事件设置一个特定的架构。您如何将架构与每个有效负载相关联?

PHP Tracker SyncEmitter(最标准的扫雪机提供的 Emitter)不允许对模式进行任何自定义设置(如下所示)

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

它被硬编码到跟踪的每个事件中。

所以我进行了调查。并进一步阅读扫雪机跟踪器。我仍然感到困惑,我知道我可以扩展 Payload 类并将我自己的模式强制作为变量,但为什么不是这样呢?我之所以问是因为我假设开源程序员做得对,但我没有正确理解它。

【问题讨论】:

    标签: php publish-subscribe snowplow


    【解决方案1】:

    我想通了。

    Tracker 类包含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);
    }
    

    接受架构作为输入。 Snowplow 希望您使用 Tracker 的默认功能,并提供上述内容作为我的问题的解决方案。

    但它仍然有一个围绕数据的架构(包含输入架构)....更多问题来自我自己的答案...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-27
      • 1970-01-01
      • 2013-05-15
      • 2010-11-27
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      相关资源
      最近更新 更多