SpringBoot整合RabbitMQ(二)单机抢票系统

本文介绍如何使用SpringBoot和RabbitMQ构建一个简单的单机抢票系统,通过MQ实现削峰和异步处理。配置包括pom.xml、application.properties,以及数据表、项目架构的设定。服务端包含Controller、Service、Dao层的实现,重点讲解了MQ部分,包括Message.java的编解码、MQSender和MQReceiver的发送与接收操作。文中提供了1k并发的压测结果,并指出项目未处理线程安全问题,强调了MQ在分布式下的应用挑战。
摘要由CSDN通过智能技术生成

原文链接:SpringBoot整合RabbitMQ(二)单机抢票系统

上一章节讲了基本的整合和各种Exchange的使用,这章主要来实现一个单机的简单的抢票系统,麻雀虽小但五脏俱全,为什么用它做抢票系统大家应该也懂,为了削峰和异步处理。

在这个项目里我用的是springboot的2版本,ORM选用JPA快速开发,JSON工具使用阿里的fastjson,当然,mq用的是rabbitMQ。导入的是springboot集成的依赖。

1. 配置部分

1.1 pom.xml
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-amqp</artifactId>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>RELEASE</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
1.2 application.properties
server.port=10000

spring.datasource.url=jdbc:mysql://xxxxx/xxxxx?characterEncoding=utf-8
spring.datasource.username=xxx
spring.datasource.password=xxxx
spring.datasource.dri
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值