触发N个事件后,重启客户端。之前触发的事件会依次触发
After triggering N events, restart the client. Previously triggered events will be triggered in sequence
axon框架版本:4.3.3
axon 服务器版本: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
抱歉,我不明白你的问题。
你能把它写得更好吗?
无论如何,请记住,从您的日志中我看到您的客户端应用程序以内存数据库启动。这意味着每次重新启动客户端数据都会丢失,并且将再次处理事件存储中的所有事件存储。
为了澄清这一点,您可以配置您的应用程序以将您的数据库保存在一个文件中
spring.datasource.url=jdbc:h2:./runtime/client/testdb;AUTO_SERVER=TRUE
Axon Framework 将注意存储有关最后处理的令牌的信息:这将阻止您的应用程序再次处理事件存储中的所有事件。
您可以在参考指南中找到更多信息
https://docs.axoniq.io/reference-guide/configuring-infrastructure-components/event-processing/event-processors#token-store
最佳。
最终解决方案:
@Configuration
public class AxonConfig {
@Autowired
public void configureProcessors(EventProcessingConfigurer eventProcessingConfigurer) {
TrackingEventProcessorConfiguration tepConfig = TrackingEventProcessorConfiguration.forSingleThreadedProcessing().andInitialTrackingToken(StreamableMessageSource::createHeadToken);
eventProcessingConfigurer.registerTrackingEventProcessorConfiguration(config -> tepConfig);
}
}
axon框架版本:4.3.3
axon 服务器版本: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
抱歉,我不明白你的问题。 你能把它写得更好吗?
无论如何,请记住,从您的日志中我看到您的客户端应用程序以内存数据库启动。这意味着每次重新启动客户端数据都会丢失,并且将再次处理事件存储中的所有事件存储。
为了澄清这一点,您可以配置您的应用程序以将您的数据库保存在一个文件中
spring.datasource.url=jdbc:h2:./runtime/client/testdb;AUTO_SERVER=TRUE
Axon Framework 将注意存储有关最后处理的令牌的信息:这将阻止您的应用程序再次处理事件存储中的所有事件。
您可以在参考指南中找到更多信息 https://docs.axoniq.io/reference-guide/configuring-infrastructure-components/event-processing/event-processors#token-store
最佳。
最终解决方案:
@Configuration
public class AxonConfig {
@Autowired
public void configureProcessors(EventProcessingConfigurer eventProcessingConfigurer) {
TrackingEventProcessorConfiguration tepConfig = TrackingEventProcessorConfiguration.forSingleThreadedProcessing().andInitialTrackingToken(StreamableMessageSource::createHeadToken);
eventProcessingConfigurer.registerTrackingEventProcessorConfiguration(config -> tepConfig);
}
}