当前位置: 首页 > news >正文

国外免费建站网站搭建福州云建站

国外免费建站网站搭建,福州云建站,温州推广平台,计算机网站开发与技术专业介绍精心整理了最新的面试资料和简历模板#xff0c;有需要的可以自行获取 点击前往百度网盘获取 点击前往夸克网盘获取 简介 Axon Framework是一个用于构建CQRS#xff08;命令查询职责分离#xff09;和事件溯源#xff08;Event Sourcing#xff09;应用的框架#xff0…精心整理了最新的面试资料和简历模板有需要的可以自行获取 点击前往百度网盘获取 点击前往夸克网盘获取 简介 Axon Framework是一个用于构建CQRS命令查询职责分离和事件溯源Event Sourcing应用的框架而Spring Boot提供了快速开发能力。二者结合可高效实现高扩展性、可维护的分布式系统。 环境准备 JDK 17Spring Boot 3.2Axon Framework 4.9Maven/Gradle 步骤详解 1. 创建Spring Boot项目 使用start.spring.io生成基础项目选择 Spring WebLombok可选 2. 添加Axon依赖 !-- pom.xml -- dependencygroupIdorg.axonframework/groupIdartifactIdaxon-spring-boot-starter/artifactIdversion4.9.0/version /dependency3. 配置Axon可选 # application.yml axon:serializer:general: jacksoneventhandling:processors:default: tracking示例银行账户管理 1. 定义命令(Command) // 开户命令 public record CreateAccountCommand(String accountId, int initialBalance) {}// 存款命令 public record DepositMoneyCommand(String accountId, int amount) {}// 取款命令 public record WithdrawMoneyCommand(String accountId, int amount) {}2. 定义事件(Event) // 账户创建事件 public record AccountCreatedEvent(String accountId, int initialBalance) {}// 存款事件 public record MoneyDepositedEvent(String accountId, int amount) {}// 取款事件 public record MoneyWithdrawnEvent(String accountId, int amount) {}3. 创建聚合根(Aggregate) Aggregate Getter NoArgsConstructor public class BankAccountAggregate {AggregateIdentifierprivate String accountId;private int balance;CommandHandlerpublic BankAccountAggregate(CreateAccountCommand command) {apply(new AccountCreatedEvent(command.accountId(), command.initialBalance()));}CommandHandlerpublic void handle(DepositMoneyCommand command) {apply(new MoneyDepositedEvent(command.accountId(), command.amount()));}CommandHandlerpublic void handle(WithdrawMoneyCommand command) {if (balance command.amount()) {throw new InsufficientBalanceException();}apply(new MoneyWithdrawnEvent(command.accountId(), command.amount()));}EventSourcingHandlerpublic void on(AccountCreatedEvent event) {this.accountId event.accountId();this.balance event.initialBalance();}EventSourcingHandlerpublic void on(MoneyDepositedEvent event) {balance event.amount();}EventSourcingHandlerpublic void on(MoneyWithdrawnEvent event) {balance - event.amount();} }4. 创建Query处理 Service public class AccountQueryService {private final MapString, Integer accounts new ConcurrentHashMap();EventHandlerpublic void on(AccountCreatedEvent event) {accounts.put(event.accountId(), event.initialBalance());}EventHandlerpublic void on(MoneyDepositedEvent event) {accounts.computeIfPresent(event.accountId(), (k, v) - v event.amount());}EventHandlerpublic void on(MoneyWithdrawnEvent event) {accounts.computeIfPresent(event.accountId(), (k, v) - v - event.amount());}QueryHandlerpublic Integer handle(GetBalanceQuery query) {return accounts.get(query.accountId());} }5. 创建REST接口 RestController RequestMapping(/accounts) RequiredArgsConstructor public class AccountController {private final CommandGateway commandGateway;private final QueryGateway queryGateway;PostMappingpublic CompletableFutureString createAccount(RequestBody CreateAccountRequest request) {return commandGateway.send(new CreateAccountCommand(UUID.randomUUID().toString(),request.initialBalance()));}GetMapping(/{accountId}/balance)public CompletableFutureInteger getBalance(PathVariable String accountId) {return queryGateway.query(new GetBalanceQuery(accountId), Integer.class);} }运行与测试 启动Spring Boot应用使用curl测试 # 创建账户 curl -X POST -H Content-Type: application/json -d {initialBalance:1000} http://localhost:8080/accounts# 查询余额替换{accountId} curl http://localhost:8080/accounts/{accountId}/balance关键配置说明 序列化配置建议使用Jackson进行JSON序列化事件存储默认使用内存存储生产环境可配置JPA或JDBC分布式处理通过axon-distributed-command-bus实现命令总线扩展 扩展方向 添加JPA事件存储集成Spring Security进行权限控制配置Saga实现复杂事务使用Axon Server进行集群管理 通过本教程您已完成了一个基础的CQRS/ES系统实现。建议通过Axon Dashboard监控事件流并逐步添加更复杂的业务逻辑。
http://www.dnsts.com.cn/news/155620.html

相关文章:

  • 刮奖网站石家庄营销网站建设价格
  • 做网站架构需要什么步骤无锡建设工程项目代码申请网站
  • 教做flash的网站做宠物服务的相关网站
  • 哪些网站百度不收录用wordpress建网站
  • 如何做好网站推广优化计算机前端和后端区别
  • 南京网站建设 个人网站开发与设计案例
  • 长春谁家做网站使用织梦系统建设网站
  • 微网站建设申请株洲市建设局网站
  • 网站建设公众号小程序属于什么新手建设什么网站好
  • 网站怎么做视频背景网站建设从建立服务器开始
  • 呼和浩特建设厅官方网站深圳创业园
  • 关于网站开发的销售wordpress图片快速主题
  • 如何给自己网站做外链网站建设实训指导书
  • 自己做网站用什么软件wordpress淘口令插件
  • 漳州本地企业网站建设服务海丰建设局网站
  • 电商的网站怎么做的好docker wordpress 备份
  • 做网站用别人图片文章会侵权吗本地网站模板修改
  • 微网站欣赏源码网站php
  • 软件开发做网站海外推广是什么工作
  • ps网站制作教程湖南常德市简介
  • 长春网站建设长春做网站公司公司广州手机网站制作
  • 外包网站制作多少钱网站的权重
  • 重庆做网站_重庆网站建设_重庆网络推广_重庆网络公司wordpress指定404
  • 齐河做网站网站动态效果用什么软件做的
  • 社交类网站开发常用的企业邮箱有哪些
  • 网站开发进度seo怎么学
  • 上海企业电话查询重庆短视频seo搜索多少钱
  • 郑州做网站的云相册网站怎么做
  • 淘宝网站如何在邮件里做超链接贵州省城乡建设局网站查
  • 广东华迪工程建设监理公司网站关键词的分类和优化