godelayqueueclient

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

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 10 Imported by: 0

README

go-delayqueue client

A client of the go-delayqueue for golang project.

Features to do

  • Push message to delayqueue.
  • Delete a message from delayqueue.
  • Send Ping test message.
  • Upate a message in the delayqueue.

How to use

import (
	delayclient "godelayqueueclient"
)
testHost := "127.0.0.1"    
fromNowDelaySeconds := 600   

// notify by HTTP  
client := delayclient.NewClientWithHostAndPort(testHost, "3450")
resp, err := client.Push(fromNowDelaySeconds, 
                          delayclient.HTTP, 
                          fmt.Sprintf("https://google.com", testHost), 
                          "hello,world")
if err != nil {
	t.Log(err)
} else {
	t.Log(resp)
  t.Log(resp.TaskId)
}

// notify by third queue (such as rabbitmq)  
var PubSubQueueName = "pubsub-queue"
resp, err := client.Push(fromNowDelaySeconds, delayclient.SubPub, PubSubQueueName, "hello,world")
if err != nil {
	t.Log(err)
} else {
	t.Log(resp)
	t.Log(resp.TaskId)
}

Contributing

Anyone is welcome to submit pull requests and suggestions, issues.

License

See LICENSE

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MessageAuthCode = "0_ONMARS_1"

Functions

func ReceiveRabbitMQMessage

func ReceiveRabbitMQMessage(queueName string, processor RabbitMQProcessor) error

Types

type Client

type Client interface {
	Push(delaySeconds int64, taskMode NotifyMode, taskTarget, contents string) (*Response, error)
	Delete(taskId string) (*Response, error)
	Ping() (*Response, error)
}

func NewClient

func NewClient() Client

func NewClientWithHostAndPort

func NewClientWithHostAndPort(host, port string) Client

type Command

type Command uint
const (
	Test Command = iota + 1
	Push
	Update
	Delete
)

type MessageBuilder

type MessageBuilder interface {
	Build() string
}

func NewDeleteMessage

func NewDeleteMessage(taskId string) MessageBuilder

func NewPingMessage

func NewPingMessage() MessageBuilder

func NewPushMessage

func NewPushMessage(delaySeconds int64, taskMode, taskTarget, contents string) MessageBuilder

type NotifyMode

type NotifyMode uint
const (
	HTTP NotifyMode = iota + 1
	SubPub
)

type RabbitMQProcessor

type RabbitMQProcessor func(msgs <-chan amqp.Delivery)

type Response

type Response struct {
	Status    ResponseStatusCode
	ErrorCode ResponseErrCode
	Message   string
	TaskId    string
}

type ResponseErrCode

type ResponseErrCode uint
const (
	NOT_READY            ResponseErrCode = 1000
	INVALID_MESSAGE      ResponseErrCode = 1010
	AUTH_FAILED          ResponseErrCode = 1012
	INVALID_DELAY_TIME   ResponseErrCode = 1014
	INVALID_COMMAND      ResponseErrCode = 1016
	INVALID_PUSH_MESSAGE ResponseErrCode = 1018
	UPDATE_FAILED        ResponseErrCode = 1020
	DELETE_FAILED        ResponseErrCode = 1022
)

type ResponseStatusCode

type ResponseStatusCode uint
const (
	Ok ResponseStatusCode = iota + 1
	Fail
)

Jump to

Keyboard shortcuts

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