在上一篇文章中,基于Axon框架,我们实现了一个具有CQRS(Command Query Responsibility Segregation,命令查询职责分离)和Event Sourcing(事件溯源)的订单微服务应用程序。
本文,我们结合Axon Server运行该应用,体验事件溯源和事件存储(Event Store)功能特性。
专栏DDD领域驱动设计-货物运输系统作者:软件架构29.8币37人已购查看
Axon Server有多种启动方式,比如Docker镜像、jar包等等。
选择需要的版本运行即可:
docker run -d --name axonserver -p 8024:8024 -p 8124:8124 axoniq/axonserver:4.2
可以访问 http://localhost:8024/,查看Axon dashboard,验证Axon Server是否成功启动。
启动我们已经编写好的微服务应用,示例项目如下所示:
启动日志如下所示,会链接本地的Axon Server,然后会注册命令处理程序。
2021-04-29 20:40:53.609 INFO 14373 --- [ main] i.a.a.c.impl.AxonServerManagedChannel : Requesting connection details from localhost:8124
2021-04-29 20:40:53.828 INFO 14373 --- [ main] i.a.a.c.impl.AxonServerManagedChannel : Successfully connected to localhost:8124
2021-04-29 20:40:53.837 INFO 14373 --- [ main] i.a.a.connector.impl.ControlChannelImpl : Connected instruction stream for context 'default'. Sending client identification
2021-04-29 20:40:53.843 INFO 14373 --- [ main] i.a.a.c.command.impl.CommandChannelImpl : CommandChannel for context 'default' connected, 0 command handlers registered
2021-04-29 20:40:53.845 INFO 14373 --- [ main] i.a.a.c.command.impl.CommandChannelImpl : Registered handler for command 'com.rickie.order.example.domain.commands.ConfirmOrderCommand' in context 'default'
2021-04-29 20:40:53.848 INFO 14373 --- [ main] i.a.a.c.command.impl.CommandChannelImpl : Registered handler for command 'com.rickie.order.example.domain.commands.ShipOrderCommand' in context 'default'
2021-04-29 20:40:53.848 INFO 14373 --- [ main] i.a.a.c.command.impl.CommandChannelImpl : Registered handler for command 'com.rickie.order.example.domain.commands.PlaceOrderCommand' in context 'default'
2021-04-29 20:40:53.866 INFO 14373 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2021-04-29 20:40:53.866 INFO 14373 --- [faces.events]-0] o.a.e.TrackingEventProcessor : Worker assigned to segment Segment[0/0] for processing
2021-04-29 20:40:53.867 INFO 14373 --- [faces.events]-0] o.a.e.TrackingEventProcessor : Using current Thread for last segment worker: TrackingSegmentWorker{processor=com.rickie.order.example.interfaces.events, segment=Segment[0/0]}
2021-04-29 20:40:53.868 INFO 14373 --- [faces.events]-0] o.a.e.TrackingEventProcessor : Fetched token: null for segment: Segment[0/0]
2021-04-29 20:40:53.875 INFO 14373 --- [ main] c.r.o.example.AxonExampleApplication : Started AxonExampleApplication in 2.455 seconds (JVM running for 2.903)
专栏Axon框架快速入门和DDD项目实践作者:软件架构19.8币25人已购查看
Axon Server控制台会显示有一个应用已经连接上来了,如图所示:
客户端通过Postman发起POST请求,如图所示:
可以在Axon Server控制台,查询Event Store,如图所示,显示该二手订单相关的事件记录。
同时,在示例应用的控制台,也可以看到如下日志输出信息:
联系客服