触发N个事件后,重新启动客户端。先前触发的事件将按顺序触发

shifeng ma :

axonframework版本:4.3.3

轴突服务器版本:4.3.5

发布事件:

@PostMapping(value = "createPost")
public void createPost(@RequestBody CreatePostDto createPostDto) {        
    eventGateway.publish(new PostCreateEvent(UUID.randomUUID().toString(), createPostDto.getTitle(),
            createPostDto.getContent()));
}

事件处理程序:

@EventHandler
public void handle(PostCreateEvent event) {
    System.out.println("in event handler");
}

问题:触发N个事件后,重新启动客户端。先前触发的事件将按顺序触发

日志:

2020-07-21 20:01:43.825  INFO 11676 --- [           main] o.s.b.a.h2.H2ConsoleAutoConfiguration    : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:testdb'
2020-07-21 20:01:43.935  INFO 11676 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-07-21 20:01:43.980  INFO 11676 --- [         task-1] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-07-21 20:01:44.023  INFO 11676 --- [         task-1] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.17.Final
2020-07-21 20:01:44.137  INFO 11676 --- [         task-1] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-07-21 20:01:44.153  INFO 11676 --- [           main] o.a.serialization.ChainingConverter      : ContentTypeConverter of type [class org.axonframework.serialization.xml.XomToStringConverter] is ignored. It seems to rely on a class that is not available in the class loader: nu/xom/Document
2020-07-21 20:01:44.163  INFO 11676 --- [           main] o.a.serialization.ChainingConverter      : ContentTypeConverter of type [class org.axonframework.serialization.xml.InputStreamToXomConverter] is ignored. It seems to rely on a class that is not available in the class loader: nu/xom/ParsingException
2020-07-21 20:01:44.232  INFO 11676 --- [         task-1] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-07-21 20:01:44.258  WARN 11676 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2020-07-21 20:01:44.521  INFO 11676 --- [           main] o.a.a.c.AxonServerConnectionManager      : Connecting using unencrypted connection...
2020-07-21 20:01:44.871  INFO 11676 --- [           main] o.a.a.c.AxonServerConnectionManager      : Requesting connection details from localhost:8124
2020-07-21 20:01:44.885  INFO 11676 --- [         task-1] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2020-07-21 20:01:44.900  INFO 11676 --- [         task-1] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-07-21 20:01:45.205  INFO 11676 --- [           main] o.a.a.c.AxonServerConnectionManager      : Reusing existing channel
2020-07-21 20:01:45.211  INFO 11676 --- [           main] o.a.a.c.AxonServerConnectionManager      : Re-subscribing commands and queries
2020-07-21 20:01:45.228  INFO 11676 --- [           main] o.a.a.c.query.AxonServerQueryBus         : Creating new query stream subscriber
2020-07-21 20:01:45.272  INFO 11676 --- [           main] o.a.a.c.command.AxonServerCommandBus     : Creating new command stream subscriber
2020-07-21 20:01:45.297  INFO 11676 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-07-21 20:01:45.298  INFO 11676 --- [           main] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-07-21 20:01:45.400  INFO 11676 --- [           main] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-07-21 20:01:45.408  INFO 11676 --- [           main] c.s.s.SpringBootAxonApplication          : Started SpringBootAxonApplication in 3.394 seconds (JVM running for 3.674)
2020-07-21 20:01:45.487  INFO 11676 --- [axon.service]-0] o.a.e.TrackingEventProcessor             : Worker assigned to segment Segment[0/0] for processing
2020-07-21 20:01:45.489  INFO 11676 --- [axon.service]-0] o.a.e.TrackingEventProcessor             : Using current Thread for last segment worker: TrackingSegmentWorker{processor=cn.sailing.springbootaxon.service, segment=Segment[0/0]}
2020-07-21 20:01:45.492  INFO 11676 --- [axon.service]-0] o.a.e.TrackingEventProcessor             : Fetched token: null for segment: Segment[0/0]
2020-07-21 20:01:45.496  INFO 11676 --- [axon.service]-0] o.a.a.c.event.axon.AxonServerEventStore  : open stream: 0
in event handler
in event handler
in event handler
in event handler
Corrado Musumeci:

抱歉,我不明白您的问题是什么。你能更好地写下来吗?

无论如何,请记住,从您的日志中,我看到您的客户端应用程序以内存中的数据库开头。这意味着每次重新启动客户端数据都会丢失,并且事件存储中的所有事件存储将再次被处理。

为了澄清这一点,您可以配置应用程序以将数据库保存在文件中spring.datasource.url=jdbc:h2:./runtime/client/testdb;AUTO_SERVER=TRUE。AxonFramework将注意存储有关最后处理的令牌的信息:这将阻止您的应用程序再次处理事件存储中的所有事件。

您可以在参考指南https://docs.axoniq.io/reference-guide/configuring-infrastructure-components/event-processing/event-processors#token-store中找到更多信息。

最好。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章