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

问题描述 投票:0回答:2

上下文: 我正在为扫雪机设置一个 PubSub 发射器。 (对于其他读者来说,PubSub 是 Google Cloud Platforms 上的一个简单队列,它接收数组形式的消息作为输入)。

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

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

实际问题:

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

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

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

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

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

php publish-subscribe snowplow
2个回答
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 的默认功能,并提供上述内容作为我的问题的解决方案。

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


0
投票

以下是如何关联架构的示例:

use Snowplow\Tracker\Tracker;
use Snowplow\Tracker\Subject;
use Snowplow\Tracker\Emitters\SyncEmitter;
$emitter = new SyncEmitter("collector-endpoint.somedomain.com", "https", "POST", 1, false);
$subject = new Subject();
$subject->setPlatform("srv");
$tracker = new Tracker($emitter, $subject, "someSophiTagUsedInSnowlowForYourDomain", "example_aid", false);
$tracker->trackUnstructEvent(
  array (
  "schema" => "iglu:com.sophi/content_update/jsonschema/2-0-2",
    "data" => array(
        "contentId" =>  "example_contentId",
        "type" => "example_type",
        "action" =>  "example_action"
    )
  ),
  array(
   array (
    "schema" => "iglu:com.globeandmail/environment/jsonschema/1-0-10",
      "data" => array(
       "environment"=> "prod",
     )
    ),
));

(c) 此示例来自 Sophi 文档

© www.soinside.com 2019 - 2024. All rights reserved.