Git Product home page Git Product logo

delay-queue's Introduction

delay-queue

延迟队列, 参考有赞延迟队列设计实现

下载

v0.1

源码安装

  • go语言版本1.7+
  • go get -d github.com/ouqiang/delay-queue
  • go build

运行

./delay-queue -c delay-queue.conf  

HTTP Server监听0.0.0.0:9277, Redis连接地址127.0.0.1:6379, 数据库编号1

HTTP接口

  • 请求方法 POST
  • 请求Body及返回值均为json

返回值

{
  "code": 0,
  "message": "添加成功",
  "data": null
}
参数名 类型 含义 备注
code int 状态码 0: 成功 非0: 失败
message string 状态描述信息
data object, null 附加信息

添加任务

URL地址 /push

{
  "topic": "order",
  "id": "15702398321",
  "delay": 3600,
  "ttr": 120,
  "body": "{\"uid\": 10829378,\"created\": 1498657365 }"
}
参数名 类型 含义 备注
topic string Job类型
id string Job唯一标识
delay int Job需要延迟的时间, 单位:秒
ttr int Job执行超时时间, 单位:秒
body string Job的内容,供消费者做具体的业务处理,如果是json格式需转义

长轮询ready queue是否有任务, 有任务立即返回或等待180秒后超时返回

URL地址 /pop

{
  "topic": "order"
}
参数名 类型 含义 备注
topic string Job类型

队列中有任务返回值

{
  "code": 0,
  "message": "操作成功",
  "data": {
    "id": "15702398321",
    "body": "{\"uid\": 10829378,\"created\": 1498657365 }"
  }
}

队列为空返回值

{
  "code": 0,
  "message": "操作成功",
  "data": null
}

删除任务

URL地址 /delete

{
  "id": "15702398321"
}
参数名 类型 含义 备注
id string Job唯一标识

完成任务

URL地址 /finish

{
  "id": "15702398321"
}
参数名 类型 含义 备注
id string Job唯一标识

delay-queue's People

Contributors

ouqiang avatar

Watchers

James Cloos avatar wuhen avatar

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.