Coder Social home page Coder Social logo

queue-task's Introduction

queue-task

简介

queue-task是一个轻量级、易扩展、支持分布式的队列调度框架。

Required

  • go version >= 1.12
  • 开启go mod

quick start

具体使用案例可看./examples文件

单机任务创建

// 创建队列
// 队列类型可以从框架中选择(目前支持redis\kafka)也可以自定义
q := queue.NewRedisQueue(&queue.RedisQueueOptions{
  Addr: "redis.dev:6379",
  Key:  "debug",
})
// 使用任务模板
testJob := job.NewDefaultJob("test", q, 10)
// 注册业务handle方法
testJob.RegisterHandleFunc(func(data []byte) {
  // ...
})

分布式任务创建

// 创建队列
q := queue.NewRedisQueue(&queue.RedisQueueOptions{
  Addr: "redis.dev:6379",
  Key:  "debug",
})
// 分布式控制策略
strategy := func() int {
  var jobCnt int
  // ...
  return jobCnt
}
// 创建分布式队列
job := job.NewDistributedJob("debug", q, job.SetCircleTime(5*time.Second), job.SetWorkerStrategy(strategy))

定制化

定制消息

实现./v1/iface/imsg.goIMessage接口,即可自定义消息。

定制队列

实现./v1/iface/iqueue.go中定义的IQueue接口即可自定义消息队列,使用方式和原生队列无差别。

定制任务

实现./v1/iface/ijob.go中定义的IJob接口,即可自定义任务,或者“继承”框架内部的BaseJob也可以自定义任务。

框架核心

框架核心文件在v1目录下,主要包含:

  • iface 框架基本接口定义,包括(任务接口队列接口消息接口
  • job 具体实现任务接口的任务模板,框架本身自带两种任务模板:
    • basejob 基础的任务模板,仅具体实现了业务方法注册
    • defaultjob 默认任务模板,实现了任务的并发
    • distributedjob 分布式任务模板,实现了在分布式环境下的任务调控
  • queue 任务队列的抽象,隐藏了具体队列,目前支持的队列:
    • redis队列
    • kafka消息队列
  • msg 消息的封装
  • task 所有任务通过此包进行统一管理
  • util 框架公用方法封装

Demo环境搭建

进入项目目录执行docker-compose up -d

详情请看docker-compose.yml文件

queue-task's People

Stargazers

Jack avatar  avatar  avatar  avatar sorrow丶hey avatar  avatar  avatar

Watchers

 avatar

Forkers

chenqiyue16

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.