【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

这篇具有很好参考价值的文章主要介绍了【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

需要全部代码请点赞关注收藏后评论区留言私信~~~

一、系统简介

分布式优惠券后台应用系统服务于两类用户群体,一类是商户,商户可以根据自己的实际情况即进行优惠券投放,另一类是平台消费用户,用户可以去领取商户发放的优惠券

二、整体架构

分布式优惠券后台应用系统采用SpringBoot作为主体开发框架,使用Kafka消息队列实现优惠券从商户到用户的传递,Mysql存储商户信息,HBase存储用户信息,优惠券信息等,Redis保存优惠券的缓存信息 系统整体架构如下

【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

 对于商户投放子系统,商户注册生成对应的商户实体信息,并保存到Mysql数据库,商户可以投放自己商家的优惠券,且优惠券有自己的Token存放于Redis中,投放的优惠券信息将由Kafka向用户消费子系统发送,而商户投放的优惠券并不在Mysql中进行存储,而是在商户投放子系统中放送消息给Kafka,用户消费子系统通过侦听Kafka消息获得Kafka分布式信息并存储到HBase中,用户通过读取Redis中的优惠券信息领取消费券,并将自己领取到的优惠券信息存放在HBase中

三、表结构设计

mysql表结果设计如何 存放商户基本信息

【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

HBase表结构设计

在HBase中建立三个表,分别是消费用户表,优惠券表和优惠券领取表

 【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

 【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

 【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

四、系统实现

1:新建MAVEN工程 引入相关依赖包

2:修改applicaiton.yml文件 包括mysql和kafka的连接相关配置

3:建立各个类包存放路径

4:核心代码实现

【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

 【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

 五、效果展示

商户投放子系统成功启动效果如下

【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

 用户子系统成功启动效果如下

【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

 发放优惠券界面如下

【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

 数据库表插入情况如下

【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)

 六、部分代码

部分代码如下 需要全部代码请点赞关注收藏后评论区留言私信~~~
 

package com.coupon.passbook.controller;

import com.coupon.passbook.log.LogConstants;
import com.coupon.passbook.log.LogGenerator;
import com.coupon.passbook.service.IUserService;
import com.coupon.passbook.vo.Response;
import com.coupon.passbook.vo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <h1>创建用户服务</h1>
 * Created by Qinyi.
 */
@Slf4j
@RestController
@RequestMapping("/passbook")
public class CreateUserController {

    /** 创建用户服务 */
    private final IUserService userService;

    /** HttpServletRequest */
    private final HttpServletRequest httpServletRequest;

    @Autowired
    public CreateUserController(IUserService userService,
                                HttpServletRequest httpServletRequest) {
        this.userService = userService;
        this.httpServletRequest = httpServletRequest;
    }

    /**
     * <h2>创建用户</h2>
     * @param user {@link User}
     * @return {@link Response}
     * */
    @ResponseBody
    @PostMapping("/createuser")
    Response createUser(@RequestBody User user) throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                user.getId(),
                LogConstants.ActionName.CREATE_USER,
                user
        );
        return userService.createUser(user);
    }
}

控制器2

package com.coupon.passbook.controller;

import com.coupon.passbook.log.LogConstants;
import com.coupon.passbook.log.LogGenerator;
import com.coupon.passbook.service.IFeedbackService;
import com.coupon.passbook.service.IGainPassTemplateService;
import com.coupon.passbook.service.IInventoryService;
import com.coupon.passbook.service.IUserPassService;
import com.coupon.passbook.vo.Feedback;
import com.coupon.passbook.vo.GainPassTemplateRequest;
import com.coupon.passbook.vo.Pass;
import com.coupon.passbook.vo.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <h1>Passbook Rest Controller</h1>
 * Created by Qinyi.
 */
@Slf4j
@RestController
@RequestMapping("/passbook")
public class PassbookController {

    /** 用户优惠券服务 */
    private final IUserPassService userPassService;

    /** 优惠券库存服务 */
    private final IInventoryService inventoryService;

    /** 领取优惠券服务 */
    private final IGainPassTemplateService gainPassTemplateService;

    /** 反馈服务 */
    private final IFeedbackService feedbackService;

    /** HttpServletRequest */
    private final HttpServletRequest httpServletRequest;

    @Autowired
    public PassbookController(IUserPassService userPassService,
                              IInventoryService inventoryService,
                              IGainPassTemplateService gainPassTemplateService,
                              IFeedbackService feedbackService,
                              HttpServletRequest httpServletRequest) {
        this.userPassService = userPassService;
        this.inventoryService = inventoryService;
        this.gainPassTemplateService = gainPassTemplateService;
        this.feedbackService = feedbackService;
        this.httpServletRequest = httpServletRequest;
    }

    /**
     * <h2>获取用户个人的优惠券信息</h2>
     * @param userId 用户 id
     * @return {@link Response}
     * */
    @ResponseBody
    @GetMapping("/userpassinfo")
    Response userPassInfo(Long userId) throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                userId,
                LogConstants.ActionName.USER_PASS_INFO,
                null
        );
        return userPassService.getUserPassInfo(userId);
    }

    /**
     * <h2>获取用户使用了的优惠券信息</h2>
     * @param userId 用户 id
     * @return {@link Response}
     * */
    @ResponseBody
    @GetMapping("userusedpassinfo")
    Response userUsedPassInfo(Long userId) throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                userId, LogConstants.ActionName.USER_USED_PASS_INFO,
                null
        );
        return userPassService.getUserUsedPassInfo(userId);
    }

    /**
     * <h2>用户使用优惠券</h2>
     * @param pass {@link Pass}
     * @return {@link Response}
     * */
    @ResponseBody
    @PostMapping("/userusepass")
    Response userUsePass(@RequestBody Pass pass) {

        LogGenerator.genLog(
                httpServletRequest,
                pass.getUserId(),
                LogConstants.ActionName.USER_USE_PASS,
                pass
        );
        return userPassService.userUsePass(pass);
    }

    /**
     * <h2>获取库存信息</h2>
     * @param userId 用户 id
     * @return {@link Response}
     * */
    @ResponseBody
    @GetMapping("/inventoryinfo")
    Response inventoryInfo(Long userId) throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                userId,
                LogConstants.ActionName.INVENTORY_INFO,
                null
        );
        return inventoryService.getInventoryInfo(userId);
    }

    /**
     * <h2>用户领取优惠券</h2>
     * @param request {@link GainPassTemplateRequest}
     * @return {@link Response}
     * */
    @ResponseBody
    @PostMapping("/gainpasstemplate")
    Response gainPassTemplate(@RequestBody GainPassTemplateRequest request)
            throws Exception {

        LogGenerator.genLog(
                httpServletRequest,
                request.getUserId(),
                LogConstants.ActionName.GAIN_PASS_TEMPLATE,
                request
        );
        return gainPassTemplateService.gainPassTemplate(request);
    }

    /**
     * <h2>用户创建评论</h2>
     * @param feedback {@link Feedback}
     * @return {@link Response}
     * */
    @ResponseBody
    @PostMapping("/createfeedback")
    Response createFeedback(@RequestBody Feedback feedback) {

        LogGenerator.genLog(
                httpServletRequest,
                feedback.getUserId(),
                LogConstants.ActionName.CREATE_FEEDBACK,
                feedback
        );
        return feedbackService.createFeedback(feedback);
    }

    /**
     * <h2>用户获取评论信息</h2>
     * @param userId 用户 id
     * @return {@link Response}
     * */
    @ResponseBody
    @GetMapping("/getfeedback")
    Response getFeedback(Long userId) {

        LogGenerator.genLog(
                httpServletRequest,
                userId,
                LogConstants.ActionName.GET_FEEDBACK,
                null
        );
        return feedbackService.getFeedback(userId);
    }

    /**
     * <h2>异常演示接口</h2>
     * @return {@link Response}
     * */
    @ResponseBody
    @GetMapping("/exception")
    Response exception() throws Exception {
        throw new Exception("Welcome To IMOOC");
    }
}

 创作不易 觉得有帮助请点赞关注收藏~~~文章来源地址https://www.toymoban.com/news/detail-496797.html

到了这里,关于【Spring Boot+Kafka+Mysql+HBase】实现分布式优惠券后台应用系统(附源码)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • # Spring Boot 中如何使用 Spring Cloud Sleuth 来实现分布式跟踪?

    在微服务架构中,通常会有多个服务相互协作,为了方便排查问题,我们需要对服务之间的调用进行跟踪。Spring Cloud Sleuth 是 Spring Cloud 生态中的分布式跟踪解决方案,它可以帮助我们追踪请求在微服务系统中的传递路径,以及记录每个服务的处理时间等信息。 本文将介绍如

    2024年02月08日
    浏览(49)
  • Spring Boot如何实现分布式系统中的服务发现和注册?

    随着互联网的快速发展,越来越多的企业开始将自己的业务迁移到分布式系统中。在这种情况下,服务发现和注册变得尤为重要。对于分布式系统中的每个服务来说,它需要知道其他服务的位置和状态,这样才能进行通信和协作。Spring Boot提供了一些工具和框架,可以帮助我

    2024年02月07日
    浏览(29)
  • Spring Boot 整合 分布式搜索引擎 Elastic Search 实现 数据聚合

    本文参考黑马 分布式Elastic search Elasticsearch是一款非常强大的开源搜索引擎,具备非常多强大功能,可以帮助我们从海量数据中快速找到需要的内容 本篇文章将讲解 Elastic Search 如何实现数据聚合,以及 在项目实战中如何通过数据聚合实现业务需求并完成功能。 以下为官方

    2024年02月11日
    浏览(36)
  • Spring Boot 整合 分布式搜索引擎 Elastic Search 实现 我附近的、酒店竞排

    本文参考黑马 分布式Elastic search Elasticsearch是一款非常强大的开源搜索引擎,具备非常多强大功能,可以帮助我们从海量数据中快速找到需要的内容 在酒店列表页的右侧,有一个小地图,点击地图的定位按钮,地图会找到你所在的位置: 点击定位后,会发送给服务端以下请求

    2024年02月06日
    浏览(30)
  • Spring Boot 整合 分布式搜索引擎 Elastic Search 实现 搜索、分页与结果过滤

    本文参考黑马 分布式Elastic search Elasticsearch是一款非常强大的开源搜索引擎,具备非常多强大功能,可以帮助我们从海量数据中快速找到需要的内容 实现黑马旅游的酒店搜索功能,完成搜索和分页 在项目首页,有一个很大的搜索框、也有分页按钮 点击搜索按钮,可以

    2024年02月06日
    浏览(38)
  • Spring Boot 3 整合 xxl-job 实现分布式定时任务调度,结合 Docker 容器化部署(图文指南)

    xxl-job 是一个分布式任务调度平台,它提供了强大的任务调度和执行能力,可以帮助我们实现任务的自动化调度和执行。本文将介绍如何在 Docker 环境下部署 xxl-job,并将其与 Spring Boot 进行整合。 数据库脚本:tables_xxl_job-2.4.0.sql Docker 镜像地址: https://hub.docker.com/r/xuxueli/xxl-jo

    2024年02月06日
    浏览(54)
  • Spring Boot 中的 Redis 分布式锁

    在分布式系统中,多个进程同时访问共享资源时,很容易出现并发问题。为了避免这些问题,我们可以使用分布式锁来保证共享资源的独占性。Redis 是一款非常流行的分布式缓存,它也提供了分布式锁的功能。在 Spring Boot 中,我们可以很容易地使用 Redis 分布式锁来管理并发

    2024年02月11日
    浏览(32)
  • spring boot + minio 分布式文件上传

    1、分布式文件系统 简单理解为:一个计算机无法存储海量的文件,通过网络将若干计算机组织起来共同去存储海量的文件,去接收海量用户的请求,这些组织起来的计算机通过网络进行通信。 好处: 一台计算机的文件系统处理能力扩充到多台计算机同时处理。 一台计算机

    2024年02月08日
    浏览(45)
  • 【Spring Boot 3】【Redis】分布式锁

    软件开发是一门实践性科学,对大多数人来说,学习一种新技术不是一开始就去深究其原理,而是先从做出一个可工作的DEMO入手。但在我个人学习和工作经历中,每次学习新技术总是要花费或多或少的时间、检索不止一篇资料才能得出一个可工作的DEMO,这占用了我大量的时

    2024年01月18日
    浏览(26)
  • Spring Boot 中的 Zookeeper 分布式锁

    分布式锁是分布式系统中常用的一个同步工具,它可以在多个进程之间协调访问共享资源,避免数据不一致或重复处理。在分布式环境中,由于网络通信的延迟和节点故障等原因,传统的锁机制无法满足需求。因此,分布式锁成为了实现分布式同步的常用方案之一。 Zookeepe

    2024年02月12日
    浏览(29)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包