Code Monkey home page Code Monkey logo

seckill's Introduction

Quick Start

一、设计方案

二、环境准备

1、启动本机redis

nohup ./redis-server &

2、启用本机redis-client

如果redis本地数据不重要,可用flushall命令清除全部数据, 方便多次进行测试

3、启动工程seckill-api

启动成功后, 访问http://localhost:8080/swagger-ui.html , 即可看到熟悉的swagger-ui界面 swagger-ui

如果熟悉swagger-ui使用方式, 下面的接口调试就可直接用Swagger来进行

三、秒杀测试

Step1: 配置活动

POST http://localhost:8080/api/v1/activity/save

{
  "activityName": "双十一秒杀第一场",
  "startTime": 1541901600000,
  "endTime": 1741951999000,
  "itemLine": [
    {
      "activityPrice": 17000,
      "itemId": 53724,
      "itemImage": "http://img.xxxx.com/static/do1_QtSq1m2xM7VL6zEI4sUH",
      "itemPrice": 42800,
      "itemTitle": "X商品标题",
      "subTitle": "X商品副标题",
      "quota": 3,
      "stock": 50
    },
    {
      "activityPrice": 4800,
      "itemId": 53725,
      "itemImage": "http://img.xxxx.com/static/MrcNjUeeoOG24zZH7nR.png",
      "itemPrice": 19800,
      "itemTitle": "Y商品标题",
      "subTitle": "Y商品副标题",
      "quota": 3,
      "stock": 50
    }
  ],
  "activityRuleConfigs": [
    {
      "configKey": "city",
      "configValue": "17,5,10,2,3,4,11"
    }
  ]
}

Step2: 启用活动

POST http://localhost:8080/api/v1/activity/changeStatus

{
  "activityId": 1,
  "enabled": true
}

Step3: 查看活动详情

GET http://localhost:8080/api/v1/activity/detail?activityId=1

Step4: 扣库存

POST http://localhost:8080/api/v1/stock/reduce

{
  "activityAccessContext": {
    "cityId": "11",
    "storeId": "999"
  },
  "activityId": 1,
  "buyerId": "buyer_001",
  "itemId": 53724,
  "orderId": "20181111123456789",
  "orderTime": 1541901700000,
  "quantity": 1
}

执行完扣库存接口后, 可以调用 http://localhost:8080/api/v1/activity/itemDetail?activityId=1&itemId=53724 验证商品销量已变为1

Step5: 回库存

POST http://localhost:8080/api/v1/stock/cancelReduce

{
  "activityId": 1,
  "orderId": "20181111123456789"
}

执行完回库存接口后, 可以调用 http://localhost:8080/api/v1/activity/itemDetail?activityId=1&itemId=53724 验证商品销量已变为0

四、其他

  • 在配置完活动并启用活动后,可以跑测试用例来模拟多个并发请求扣/回库存; 测试case见com.cgx.marketing.application.activity.StockAppServiceTest

seckill's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.