package
0.1.57
Repository: https://github.com/toniz/gosuit.git
Documentation: pkg.go.dev

# README

简介

目前只做了任务队列的设计。 目前支持了kafka,rabbitmq和mqtt

使用准备

  • 使用kafka
go get github.com/segmentio/kafka-go
  • 使用rabbitmq
go get github.com/streadway/amqp
  • 使用mqtt
github.com/eclipse/paho.mqtt.golang

PS:没有用到就不需要下载

创建对象:

  • 创建rabbitmq对象:
import (
    . "github.com/toniz/gosuit/queue"
    _ "github.com/toniz/gosuit/queue/rabbitmq"
)

mq, _ := NewMessageQueue("rabbitmq")
  • 创建kafka对象:
import (
    . "github.com/toniz/gosuit/queue"
    _ "github.com/toniz/gosuit/queue/kafka"
)
mq, _ := NewMessageQueue("kafka")

建立链接:

  • 链接kafka (kafka可以没有用户名和密码)
endpoint := "10.96.16.9:9092"
user := ""
password := ""
err := mq.Connect(endpoint, user, password)
  • 链接rabbitmq
endpoint := "10.111.50.176:5672"
user := "user"
password := "6DuA9eBfLu"
err := mq.Connect(endpoint, user, password)

发送消息:

  • 发送消息 kafka 和rabbitmq 用法一样:
queueName := "topic-test"
msg := "Test Send Message"
err := mq.SendTask(queueName, msg)

接受消息:

  • 启用协程接受消息, kafka 和 rabbitmq 用法一样:
err := mq.Worker(queueName, func (s []byte) error{
    log.Printf("Received a message: %s", s)
    dot_count := bytes.Count(s, []byte("."))
    t := time.Duration(dot_count)
    time.Sleep(t * time.Second)
    log.Printf("Done")
    return nil
})

使用例子可以参考

rabbitmq 测试用例
kafka测试用例

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

't' has three values to choose from: rabbitmq, kafka, matt.
No description provided by the author

# Interfaces

Worker Definition: fn function return: 0 continue; 1 exit; .