简体   繁体   English

Axon Framework从domain_event_entry表读取所有事件,而不是在其中序列化有效负载

[英]Axon Framework read all events from domain_event_entry table, and not to serialize payload in it

I am using Axon Framework without Axon Server and with Spring Boot auto configuration. 我正在使用没有Axon Server和Spring Boot自动配置的Axon Framework。 I have an H2 database, using the Spring auto configuration. 我有一个使用Spring自动配置的H2数据库。

It seem like the EventStore API only provide the EventStore#readEvents(String aggregateId) method, to read all events for a specific aggregate. 似乎EventStore API仅提供EventStore#readEvents(String aggregateId)方法,以读取特定集合的所有事件。 However, I would like to read all events, fron all aggregates. 但是,我想阅读所有事件,而不是所有汇总。

How can I achieve this? 我该如何实现?

And secondly, I don't want to serialize the data in the payload, I want to store it in JSON, how can I do that? 其次,我不想序列化有效负载中的数据,我想将其存储在JSON中,我该怎么做?

Thanks. 谢谢。

The EventStore interface itself indeed only contains methods to read events for a given Aggregate. 实际上, EventStore接口本身仅包含用于读取给定Aggregate的事件的方法。 That interface however implements the StreamableMessageSource interface (which you can find here ). 但是,该接口实现了StreamableMessageSource接口(您可以在此处找到)。

Through this interface, the EventStore provides you the openStream(TrackingToken) method. 通过此接口, EventStore为您提供openStream(TrackingToken)方法。 The TrackingToken specifies at which point in the stream you want to start. TrackingToken指定您要在流中的哪一点开始。 As a short cut, if you provide null as the TrackingToken , the stream will open at the beginning of time (for said event stream of course). 作为捷径,如果您提供null作为TrackingToken ,则流将在时间开始时打开(当然是针对所述事件流)。

Note though, that I would typically suggest against querying the EventStore directly. 但是请注意,我通常建议不要直接查询EventStore Axon provides a perfectly fine annotation based approach to handling events, by drafting up an @EventHandler annotated method in an Event Handler class you register to the store (something which is done automatically for you when using Spring Boot auto configuration). Axon通过在注册到商店的事件处理程序类中起草@EventHandler注释的方法,从而提供了一种基于注释的完美方法来处理事件(使用Spring Boot自动配置时,该操作会自动为您完成)。

As a short hand to read all events in a single Event Handling Function, you can do the following: 作为读取单个事件处理功能中所有事件的捷径,您可以执行以下操作:

@EventHandler
public void on(Object event) {
    // Perform event handling logic
}

In this snippet, I am performing somewhat of a trick. 在此片段中,我正在执行一些技巧。 Axon will by default provide an Event to the most specific implementation of said event. 默认情况下,Axon将为该事件的最具体实现提供一个事件。 As everything in Java implements Object , simply having a single Event Handler where the first parameter (note that the first parameter is always the Event payload) is of type Object will do the trick. 由于Java中的所有内容都实现了Object ,因此只需一个事件处理程序即可解决问题,其中第一个参数(请注意,第一个参数始终是Event有效负载)的类型为Object


Now for the last question you've posted (I would suggest to make separate question for this in the future to keep focus on Stack Overflow): 现在,对于您发布的最后一个问题(我建议将来对此做一个单独的问题,以专注于堆栈溢出):

And secondly, I don't want to serialize the data in the payload, I want to store it in JSON, how can I do that? 其次,我不想序列化有效负载中的数据,我想将其存储在JSON中,我该怎么做?

Do you mean you want to handle the event as JSON in an Event Handler? 您是说要在事件处理程序中将事件作为JSON处理吗? Or, that you want to retrieve a stream of JSON from the EventStore directly? 还是您想直接从EventStore检索JSON流? Note that it's impossible to store the objects as is, so serialization will always take place. 请注意,不可能按原样存储对象,因此将始终进行序列化。

If it's disabling deserialization, then I can tell you that you'll have to query the actual database yourself for this, or heavily customize the EventStorageEngine (the storage engine is what the EventStore uses to retrieve events from your database). 如果禁用反序列化,那么我可以告诉您,您必须为此查询实际的数据库,或者大量定制EventStorageEngineEventStore用于从数据库检索事件的存储引擎)。 The AxonIQ team is thinking of adding just such a feature, but I can assure you that this hasn't been implemented yet. AxonIQ团队正在考虑添加这种功能,但是我可以向您保证,尚未实现此功能。

Hope this clarifies your options @polosoft! 希望这可以澄清您的选择@polosoft!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM