如何获取 Event Store 中特定类别的预测?

How can I get the projections for specific category in Event Store?

我在活动商店做了如下投影:

fromCategory('Ping')
.foreachStream()
.when({
   $init: function() { 
     return { 
       min: 0,
       max: 0,
       sum: 0,
       cnt: 0
    }; 
   },
   $any: function(s, e) {
      if (s.max < e.body.AcPower) {
        s.max = e.body.AcPower;
      }
      if (s.min > e.body.AcPower) {
        s.min = e.body.AcPower;
      }
      s.sum += e.body.AcPower;
      s.cnt += 1;
      s.avg = s.sum/s.cnt;
   }
});

如何获取特定流的结果? 流 ID 为:"Ping-255.1"、"Ping-255.2"..."Ping-255.1000"

正在查看: http://localhost:2113/projection/stats-cont 我得到:

{
  "coreProcessingTime": 4072,
  "version": 0,
  "epoch": -1,
  "effectiveName": "stats-cont",
  "writesInProgress": 0,
  "readsInProgress": 0,
  "partitionsCached": 1000,
  "status": "Running",
  "stateReason": "",
  "name": "stats-cont",
  "mode": "Continuous",
  "position": "$ce-Ping: 132233",
  "progress": 100.0,
  "lastCheckpoint": "$ce-Ping: 131999",
  "eventsProcessedAfterRestart": 132234,
  "statusUrl": "http://localhost:2113/projection/stats-cont",
  "stateUrl": "http://localhost:2113/projection/stats-cont/state",
  "resultUrl": "http://localhost:2113/projection/stats-cont/result",
  "queryUrl": "http://localhost:2113/projection/stats-cont/query%3Fconfig=yes",
  "enableCommandUrl": "http://localhost:2113/projection/stats-cont/command/enable",
  "disableCommandUrl": "http://localhost:2113/projection/stats-cont/command/disable",
  "checkpointStatus": "",
  "bufferedEvents": 0,
  "writePendingEventsBeforeCheckpoint": 0,
  "writePendingEventsAfterCheckpoint": 0
}

以下无效: http://localhost:2113/projection/stats-cont/state?partition=255.1

提前致谢。

我通过调试 Event-store 找到了答案:-)。

分区实际上是类别("Ping-255.1")所以真正URL得到状态投影状态是: http://localhost:2113/projection/stats-cont/state?partition=Ping-255.1

在事件存储 4.0 及更高版本中,启用按类别内置投影:

curl "http://localhost:2113/projection/$by_category/command/enable" -X POST -H "Content-Length: 0" -H "Authorization: Basic YWRtaW46Y2hhbmdlaXQ="

此示例中的授权 header 包含默认 admin:changeit 凭据。

启用按类别投影后,将为 Ping-* 事件创建一个 $ce-Ping 流。使用此 URL:

查看 $ce-Ping 流

http://127.0.0.1:2113/web/index.html#/streams/$ce-Ping