2015-04-21 32 views
1

我在事件商店做出如下預測:如何在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是: 「平255.1」, 「平255.2」 ...... 「平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

在此先感謝。

回答

0

在事件存儲4.0和更高版本,通過內置在投影類啓用:

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

本示例中的授權標頭包含默認的admin:changeit憑證。

啓用按類別投影后,會爲Ping- *事件創建$ ce-Ping流。使用以下URL查看$ ce-Ping流:

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

2

我通過調試Event-store :-)找到了答案。

分區實際上是與類別(「平255.1」),所以真正的URL來獲取狀態的投影狀態是: http://localhost:2113/projection/stats-cont/state?partition=Ping-255.1

+0

謝謝。我指的是這篇文章:http://codeofrob.com/entries/creating-a-projection-per-stream-in-the-eventstore.html。猜猜它有點老了。 – andho

+0

我花了一天的時間尋找這個...... ES很棒,但它的文檔是一個完整的錯誤。 – yanoo