步骤 6:管理event sourcing

    在我的例子中,我使用了关系数据库作为事件存储,定义如下:

    这是事件存储的数据源定义:

    entityManagerFactory(提供数据库连接的bean)是这样定义的:

    In the event store, you can find the tables DOMAINEVENTENTRY and SNAPSHOTEVENTENTRY (created by the framework the first time), each of which has the following columns:

    在事件存储中,您可以找到表 DOMAINEVENTENTRY 和 (由框架在第一次时创建),其中每个表都具有以下列:

    一些示例内容如 图6 所示:

    图 6. DOMAINEVENTENTRY 表内容示例

    步骤 6:管理event sourcing - 图2

    The event bus is the mechanism that dispatches the events to their listeners. Each event can have one or more listeners associated with it. Using the default implementation, you would write:

    框架提供两个可用实现:

    图7 展示 clustering event bus。

    图 7. Clustering event bus

    以下是如何声明解决方案:

    ClusteringEventBus 也可以定义 EventBusTerminal。这样,您可以分发事件来将事件传输到与 AMQP 兼容的消息代理(如Rabbit MQ)。我已经在我的一个应用程序配置(只配置,没有代码更改)中使用了这个功能。有关部署此解决方案的信息,请参阅“Bluemix容器部署”。