mq

package module
v0.0.0-...-af31ddf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2019 License: MIT Imports: 5 Imported by: 2

README

bulrush-mq

Lightweight queue to improve system throughput

Example

// @Summary MQ测试
// @Description MQ测试
// @Tags MQ
// @Accept mpfd
// @Produce json
// @Param accessToken query string true "令牌"
// @Success 200 {string} json "{"message": "ok"}"
// @Failure 400 {string} json "{"message": "failure"}"
// @Router /mgoTest [get]
func mqHello(router *gin.RouterGroup, event events.EventEmmiter, q *mq.MQ) {
	q.Register("mqTest", func(mess mq.Message) error {
		fmt.Println(mess.Body)
		return nil
	})
	router.GET("/mqTest", func(c *gin.Context) {
		q.Push(mq.Message{
			Type: "mqTest",
			Body: map[string]interface{}{
				"message": "ok",
			},
		})
		c.JSON(http.StatusOK, gin.H{"message": "ok"})
	})
}
// RegisterMq defined hello routes
func RegisterMq(router *gin.RouterGroup, event events.EventEmmiter, ri *bulrush.ReverseInject) {
	ri.Register(mqHello)
}

API

// set diff property if you want
type MQ struct {
	bulrush.PNBase
	Model      Model
	Exector    []Exector
	TypeTactic []TypeTactic
	Interval   []chan bool
}

MIT License

Copyright (c) 2018-2020 Double

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const (
	// INIT status
	INIT = "INIT"
	// PROCESSING status
	PROCESSING = "PROCESSING"
	// SUCCEED status
	SUCCEED = "SUCCEED"
	// FAILED status
	FAILED = "FAILED"
)

Variables

View Source
var DEFAULTTYPETACTIC = TypeTactic{
	Tactic: Tactic{
		Interval:   3,
		AsyncCount: 1,
	},
}

DEFAULTTYPETACTIC defined default Tactic

Functions

This section is empty.

Types

type Exector

type Exector struct {
	Type    string
	Handler func(*Message) error
}

Exector defined loop handler

type MQ

type MQ struct {
	Model      Model
	Exector    []Exector
	TypeTactic []TypeTactic
	Interval   []chan bool
}

MQ defined message queue struct

func New

func New() *MQ

New defined obtain a MQ

func (*MQ) AddTactics

func (mq *MQ) AddTactics(tp string, tac Tactic) *MQ

AddTactics add Tactics to system

func (*MQ) Plugin

func (mq *MQ) Plugin() *MQ

Plugin defined Mq Plugin

func (*MQ) Push

func (mq *MQ) Push(mess Message)

Push events

func (*MQ) Register

func (mq *MQ) Register(tp string, handler func(*Message) error) *MQ

Register event handler

func (*MQ) SetModel

func (mq *MQ) SetModel(model Model) *MQ

SetModel set mq model

type Memo

type Memo struct {
	Model
	// contains filtered or unexported fields
}

Memo defined memory model

func (*Memo) Count

func (m *Memo) Count(mtype string, status string) uint

Count defined count message

func (*Memo) Find

func (m *Memo) Find(mtype string, status string) *Message

Find defined find message

func (*Memo) Save

func (m *Memo) Save(mes Message)

Save defined store message

func (*Memo) Update

func (m *Memo) Update(ms *Message, status string) error

Update defined update message

type Message

type Message struct {
	ID        int
	Type      string
	Body      map[string]interface{}
	Status    string
	CreatedAt time.Time
}

Message defined message entity struct

type Model

type Model interface {
	Save(Message)
	Find(string, string) *Message
	Count(string, string) uint
	Update(*Message, string) error
}

Model defined model store

type Tactic

type Tactic struct {
	// Interval every interval do work
	Interval int
	// AsyncCount defined all count in aount
	AsyncCount uint
}

Tactic defined interval type

type TypeTactic

type TypeTactic struct {
	Type   string
	Tactic Tactic
}

TypeTactic defined interval type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL