cmq_go

package module
v0.0.0-...-0b7016b Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2019 License: MIT Imports: 17 Imported by: 0

README

cmq-go

Tencent CMQ Golang SDK

与腾讯云官方SDK接口保持一致

Getting Started

所有的API中都有test case,这里使用CreateQueue举例。

var secretId = "YourTencentSecretId"
var secretKey = "YourTencentSecretKey"
var endpointQueue = "https://cmq-queue-sh.api.qcloud.com"
var endpointQueueInner = "http://cmq-queue-sh.api.tencentyun.com"

// 创建队列
func Test_CreateQueue(t *testing.T) {
    //创建账户
	account := cmq_go.NewAccount(endpointQueue, secretId, secretKey)
	
	//设置队列metadata
	meta := cmq_go.QueueMeta{}
	meta.PollingWaitSeconds = 10
	meta.VisibilityTimeout = 10
	meta.MaxMsgSize = 1048576
	meta.MsgRetentionSeconds = 345600

    //创建队列queue-test-001
	err := account.CreateQueue("queue-test-001", meta)
	if err != nil {
		t.Errorf("queue-test-001 created failed, %v", err.Error())
		return
	}
	t.Log("queue-test-001 created")

    //创建队列queue-test-002
	err = account.CreateQueue("queue-test-002", meta)
	if err != nil {
		t.Errorf("queue-test-002 created failed, %v", err.Error())
		return
	}
	t.Log("queue-test-002 created")
}

Test Case

测试单个方法
go test -v -test.run Test_CreateQueue

API Status

队列模型
队列相关接口
  • CreateQueue
  • ListQueue
  • GetQueueAttributes
  • SetQueueAttributes
  • DeleteQueue
消息相关接口
  • SendMessage
  • BatchSendMessage
  • ReceiveMessage
  • BatchReceiveMessage
  • DeleteMessage
  • BatchDeleteMessage
主题模型
主题相关接口
  • CreateTopic
  • SetTopicAttributes
  • ListTopic
  • GetTopicAttributes
  • DeleteTopic
消息相关接口
  • PublishMessage
  • BatchPublishMessage
订阅相关接口
  • Subscribe
  • ListSubscriptionByTopic
  • SetSubscriptionAttributes
  • GetSubscriptionAttributes
  • Unsubscribe

Documentation

Index

Constants

View Source
const (
	/** 缺省消息接收长轮询等待时间 */
	DEFAULT_POLLING_WAIT_SECONDS = 0
	/** 缺省消息可见性超时 */
	DEFAULT_VISIBILITY_TIMEOUT = 30
	/** 缺省消息最大长度,单位字节 */
	DEFAULT_MAX_MSG_SIZE = 1048576
	/** 缺省消息保留周期,单位秒 */
	DEFAULT_MSG_RETENTION_SECONDS = 345600
)
View Source
const (
	NotifyStrategyDefault         = "BACKOFF_RETRY"
	NotifyContentFormatDefault    = "JSON"
	NotifyContentFormatSimplified = "SIMPLIFIED"
)
View Source
const (
	CURRENT_VERSION = "SDK_GO_1.3"
)
View Source
const (
	DEFAULT_ERROR_CODE = -1
)
View Source
const (
	SIGN_ALGORITHM_SHA1 = "sha1"
)

Variables

This section is empty.

Functions

func Sign

func Sign(src, key, method string) string

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

func NewAccount

func NewAccount(endpoint, secretId, secretKey string) *Account

func (*Account) CreateQueue

func (this *Account) CreateQueue(queueName string, queueMeta QueueMeta) (err error, code, moduleErrCode int)

func (*Account) CreateSubscribe

func (this *Account) CreateSubscribe(topicName, subscriptionName, endpoint, protocol, notifyContentFormat string) (
	err error, code, moduleErrCode int)

func (*Account) CreateTopic

func (this *Account) CreateTopic(topicName string, maxMsgSize int) (err error, code, moduleErrCode int)

func (*Account) DeleteQueue

func (this *Account) DeleteQueue(queueName string) (err error, code, moduleErrCode int)

func (*Account) DeleteSubscribe

func (this *Account) DeleteSubscribe(topicName, subscriptionName string) (err error, code, moduleErrCode int)

func (*Account) DeleteTopic

func (this *Account) DeleteTopic(topicName string) (err error, code, moduleErrCode int)

func (*Account) GetQueue

func (this *Account) GetQueue(queueName string) (queue *Queue)

func (*Account) GetSubscription

func (this *Account) GetSubscription(topicName, subscriptionName string) *Subscription

func (*Account) GetTopic

func (this *Account) GetTopic(topicName string) (topic *Topic)

func (*Account) ListQueue

func (this *Account) ListQueue(searchWord string, offset, limit int) (
	totalCount int, queueList []string, err error, code int)

func (*Account) ListTopic

func (this *Account) ListTopic(searchWord string, offset, limit int) (
	totalCount int, topicList []string, err error, code int)

func (*Account) SetProxy

func (this *Account) SetProxy(proxyUrl string)

func (*Account) UnsetProxy

func (this *Account) UnsetProxy()

type CMQClient

type CMQClient struct {
	Endpoint   string
	Path       string
	SecretId   string
	SecretKey  string
	Method     string
	SignMethod string
	Proxy      string
	CmqHttp    *CMQHttp
}

func NewCMQClient

func NewCMQClient(endpoint, path, secretId, secretKey, method string) *CMQClient

type CMQHttp

type CMQHttp struct {
	// contains filtered or unexported fields
}

func NewCMQHttp

func NewCMQHttp() *CMQHttp

func (*CMQHttp) DebugMode

func (c *CMQHttp) DebugMode() bool

func (*CMQHttp) SetDebug

func (c *CMQHttp) SetDebug(b bool)

Debug open the CMQHttp debug mode

type CMQTool

type CMQTool struct {
}

type Message

type Message struct {
	/** 服务器返回的消息ID */
	MsgId string
	/** 每次消费唯一的消息句柄,用于删除等操作 */
	ReceiptHandle string
	/** 消息体 */
	MsgBody string
	/** 消息发送到队列的时间,从 1970年1月1日 00:00:00 000 开始的毫秒数 */
	EnqueueTime int64
	/** 消息下次可见的时间,从 1970年1月1日 00:00:00 000 开始的毫秒数 */
	NextVisibleTime int64
	/** 消息第一次出队列的时间,从 1970年1月1日 00:00:00 000 开始的毫秒数 */
	FirstDequeueTime int64
	/** 出队列次数 */
	DequeueCount int
	MsgTag       []string
}

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue(queueName string, client *CMQClient) (queue *Queue)

func (*Queue) BatchDeleteMessage

func (this *Queue) BatchDeleteMessage(receiptHandles []string) (err error, code, moduleErrCode int)

func (*Queue) BatchReceiveMessage

func (this *Queue) BatchReceiveMessage(numOfMsg, pollingWaitSeconds int) (msgs []Message, err error, code, moduleErrCode int)

func (*Queue) BatchSendDelayMessage

func (this *Queue) BatchSendDelayMessage(msgBodys []string, delaySeconds int) (messageIds []string, err error, code, moduleErrCode int)

func (*Queue) BatchSendMessage

func (this *Queue) BatchSendMessage(msgBodys []string) (messageIds []string, err error, code, moduleErrCode int)

func (*Queue) DeleteMessage

func (this *Queue) DeleteMessage(receiptHandle string) (err error, code, moduleErrCode int)

func (*Queue) GetQueueAttributes

func (this *Queue) GetQueueAttributes() (queueMeta QueueMeta, err error, code, moduleErrCode int)

func (*Queue) ReceiveMessage

func (this *Queue) ReceiveMessage(pollingWaitSeconds int) (msg Message, err error, code, moduleErrCode int)

func (*Queue) RewindQueue

func (this *Queue) RewindQueue(backTrackingTime int) (err error, code, moduleErrCode int)

func (*Queue) SendDelayMessage

func (this *Queue) SendDelayMessage(msgBody string, delaySeconds int) (messageId string, err error, code, moduleErrCode int)

func (*Queue) SendMessage

func (this *Queue) SendMessage(msgBody string) (messageId string, err error, code, moduleErrCode int)

func (*Queue) SetQueueAttributes

func (this *Queue) SetQueueAttributes(queueMeta QueueMeta) (err error, code, moduleErrCode int)

type QueueMeta

type QueueMeta struct {
	/** 最大堆积消息数 */
	MaxMsgHeapNum int
	/** 消息接收长轮询等待时间 */
	PollingWaitSeconds int
	/** 消息可见性超时 */
	VisibilityTimeout int
	/** 消息最大长度 */
	MaxMsgSize int
	/** 消息保留周期 */
	MsgRetentionSeconds int
	/** 队列创建时间 */
	CreateTime int
	/** 队列属性最后修改时间 */
	LastModifyTime int
	/** 队列处于Active状态的消息总数 */
	ActiveMsgNum int
	/** 队列处于Inactive状态的消息总数 */
	InactiveMsgNum int
	/** 已删除的消息,但还在回溯保留时间内的消息数量 */
	RewindMsgNum int
	/** 消息最小未消费时间 */
	MinMsgTime int
	/** 延时消息数量 */
	DelayMsgNum int
	/** 回溯时间 */
	RewindSeconds int
}

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

func NewSubscription

func NewSubscription(topicName, subscriptionName string, client *CMQClient) *Subscription

func (*Subscription) ClearFilterTags

func (this *Subscription) ClearFilterTags() (err error, code, moduleErrCode int)

func (*Subscription) GetSubscriptionAttributes

func (this *Subscription) GetSubscriptionAttributes() (meta *SubscriptionMeta, err error, code, moduleErrCode int)

func (*Subscription) SetSubscriptionAttributes

func (this *Subscription) SetSubscriptionAttributes(meta SubscriptionMeta) (err error, code, moduleErrCode int)

type SubscriptionMeta

type SubscriptionMeta struct {
	//Subscription 订阅的主题所有者的appId
	TopicOwner string
	//订阅的终端地址
	Endpoint string
	//订阅的协议
	Protocal string
	//推送消息出现错误时的重试策略
	NotifyStrategy string
	//向 Endpoint 推送的消息内容格式
	NotifyContentFormat string
	//描述了该订阅中消息过滤的标签列表(仅标签一致的消息才会被推送)
	FilterTag []string
	//Subscription 的创建时间,从 1970-1-1 00:00:00 到现在的秒值
	CreateTime int
	//修改 Subscription 属性信息最近时间,从 1970-1-1 00:00:00 到现在的秒值
	LastModifyTime int
	//该订阅待投递的消息数
	MsgCount   int
	BindingKey []string
}

func NewSubscriptionMeta

func NewSubscriptionMeta() *SubscriptionMeta

type Topic

type Topic struct {
	// contains filtered or unexported fields
}

func NewTopic

func NewTopic(topicName string, client *CMQClient) (queue *Topic)

func (*Topic) BatchPublishMessage

func (this *Topic) BatchPublishMessage(msgList []string) (msgIds []string, err error, code, moduleErrCode int)

func (*Topic) GetTopicAttributes

func (this *Topic) GetTopicAttributes() (meta TopicMeta, err error, code, moduleErrCode int)

func (*Topic) ListSubscription

func (this *Topic) ListSubscription(offset, limit int, searchWord string) (totalCount int, subscriptionList []string, err error, code, moduleErrCode int)

func (*Topic) PublishMessage

func (this *Topic) PublishMessage(message string) (msgId string, err error, code, moduleErrCode int)

func (*Topic) SetTopicAttributes

func (this *Topic) SetTopicAttributes(maxMsgSize int) (err error, code, moduleErrCode int)

type TopicMeta

type TopicMeta struct {
	// 当前该主题的消息堆积数
	MsgCount int
	// 消息最大长度,取值范围1024-1048576 Byte(即1-1024K),默认1048576
	MaxMsgSize int
	//消息在主题中最长存活时间,从发送到该主题开始经过此参数指定的时间后,
	//不论消息是否被成功推送给用户都将被删除,单位为秒。固定为一天,该属性不能修改。
	MsgRetentionSeconds int
	//创建时间
	CreateTime int
	//修改属性信息最近时间
	LastModifyTime int
	LoggingEnabled int
	FilterType     int
}

func NewTopicMeta

func NewTopicMeta() *TopicMeta

Jump to

Keyboard shortcuts

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