mqtt

package module
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

README

mqtt

盘古框架Mqtt集成,方便用户在盘古框架中接入Mqtt功能

本框架对Mqtt做了一定的封装,使用参看使用文档

快速开始

Mqtt使用非常简单,只需要定义配置和依赖项

配置有很多,但是大部分都有默认值,可以参考配置文档

配置代码如下

mqtt:
  broker:
    - tcp://192.168.95.102:31883
    - ws://192.168.95.102:38083
  options:
    username: test_username
    password: test_password
    clientid: ${HOSTNAME}

依赖项的代码如下

package main

import (
  `github.com/pangum/mqtt`
)

type agent struct {
  client *mqtt.Client
}

func newAgent(client *mqtt.Client) *agent {
  return &agent{
    client: client,
  }
}

func (a *agent) subscribe() error {
  return a.client.Subscribe(`topic`, opts...)
}

Mqtt有非常多的配置项,请参看使用文档

文档

点击这里查看最新文档

使用示例

点击这里查看最新的代码示例

交流

微信群

捐助

支持宝 微信

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes() *optionSerializer

Bytes 原始数据

func Default

func Default() *optionLabel

Default 配置使用默认客户端

func Delay

func Delay(delay time.Duration) *optionDelay

Delay 配置延时发送

func DisableDefault added in v0.2.0

func DisableDefault() *optionDefaults

DisableDefault 是否处理默认值

func DisableDefaults added in v0.2.0

func DisableDefaults() *optionDefaults

DisableDefaults 是否处理默认值

func DisableValidate added in v0.2.0

func DisableValidate() *optionValidate

DisableValidate 是否验证数据

func DisableValidates added in v0.2.0

func DisableValidates() *optionValidate

DisableValidates 是否验证数据

func JSON

func JSON() *optionSerializer

JSON 使用JSON序列化

func Label

func Label(label string) *optionLabel

Label 配置使用哪一个客户端

func Msgpack

func Msgpack() *optionSerializer

Msgpack 使用Msgpack序列化

func NotSave

func NotSave() *optionSave

NotSave 配置不存储订阅关系

func Proto

func Proto() *optionSerializer

Proto 谷歌Protocol Buffer序列化

func PublishOptions added in v0.0.7

func PublishOptions(opts ...publishOption) []publishOption

PublishOptions 因为接口没有暴露,在外面不方便处理,特意留一个组装各种选项的方法

func Qos0

func Qos0() *optionQos

Qos0 0等级消息,MQTT不保证消息到达

func Qos1

func Qos1() *optionQos

Qos1 1等级消息,MQTT保证消息至少会被消费一次

func Qos2

func Qos2() *optionQos

Qos2 2等级消息,MQTT保证消息有且只能被消费一次,此等级最高,会消耗性能,建议不要大量使用

func Retained added in v0.0.7

func Retained() *optionRetained

Retained 配置是否保存到服务器

func String

func String() *optionSerializer

String 字符串数据

func Time added in v0.0.7

func Time(t time.Time) *optionDelay

Time 配置某个时刻执行

func Timestamp added in v0.0.7

func Timestamp(timestamp time.Time) *optionDelay

Timestamp 配置某个时刻执行

func Until added in v0.0.7

func Until(until time.Time) *optionDelay

Until 配置直到某个时间点触发

func XML

func XML() *optionSerializer

XML 使用XML序列化

Types

type Client

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

Client MQTT客户端封装

func (*Client) Disconnect

func (c *Client) Disconnect(duration time.Duration, opts ...option) (err error)

func (*Client) Publish

func (c *Client) Publish(topic string, payload interface{}, opts ...publishOption) (err error)

func (*Client) Resubscribe

func (c *Client) Resubscribe() (successes []string, fails []string, err error)

func (*Client) Subscribe

func (c *Client) Subscribe(topic string, handler handler, opts ...subscribeOption) (err error)

func (*Client) Subscription

func (c *Client) Subscription(opts ...brokersOption) []string

func (*Client) Urls

func (c *Client) Urls(opts ...brokersOption) []string

type Message

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

Message 消息封装

func (*Message) Duplicate added in v0.2.0

func (m *Message) Duplicate() bool

func (*Message) Fill added in v0.2.0

func (m *Message) Fill(value interface{}, opts ...messageOption) (err error)

func (*Message) MessageId added in v0.2.0

func (m *Message) MessageId() uint16

func (*Message) Qos added in v0.2.0

func (m *Message) Qos() byte

func (*Message) Retained added in v0.2.0

func (m *Message) Retained() bool

func (*Message) Topic added in v0.2.0

func (m *Message) Topic() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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