management

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 11 Imported by: 0

README

Management

Management provide restful api for users to query the current server state and do other operations.

API list

Get All Active Clients

Request:

GET /clients?page=xxx&page_size=xxx
page: default to 1
page_size: default to 20

Response:

{
    "code": 0,
    "message": "",
    "data": {
        "pager": {
            "page": 1,
            "page_size": 10,
            "count": 1
        },
        "result": [
            {
                "client_id": "id",
                "username": "root",
                "password": "rootpwd",
                "keep_alive": 65,
                "clean_session": false,
                "will_flag": false,
                "will_retain": false,
                "will_qos": 0,
                "will_topic": "",
                "will_payload": "",
                "remote_addr": "127.0.0.1:49252",
                "local_addr": "127.0.0.1:1883",
                "connected_at": "2019-08-10T23:29:56+08:00",
                "disconnected_at": "1970-01-01T08:00:00+08:00"
            }
        ]
    }
}

Get Client By ID

Request:

GET /client/:id

Response:

{
    "code": 0,
    "message": "",
    "data": {
        "client_id": "id",
        "username": "root",
        "password": "rootpwd",
        "keep_alive": 65,
        "clean_session": false,
        "will_flag": false,
        "will_retain": false,
        "will_qos": 0,
        "will_topic": "",
        "will_payload": "",
        "remote_addr": "127.0.0.1:49252",
        "local_addr": "127.0.0.1:1883",
        "connected_at": "2019-08-10T23:29:56+08:00",
        "disconnected_at": "1970-01-01T08:00:00+08:00"
    }
}
Get All Sessions

Request:

GET /sessions?page=xxx&page_size=xxx
page: default to 1
page_size: default to 20

response:

{
    "code": 0,
    "message": "",
    "data": {
        "pager": {
            "page": 1,
            "page_size": 20,
            "count": 1
        },
        "result": [
            {
                "client_id": "id",
                "status": "online",
                "clean_session": false,
                "subscriptions": 0,
                "max_inflight": 32,
                "inflight_len": 0,
                "max_msg_queue": 1000,
                "msg_queue_len": 0,
                "max_await_rel": 100,
                "await_rel_len": 0,
                "msg_dropped_total": 0,
                "msg_delivered_total": 0,
                "connected_at": "2019-08-10T23:29:56+08:00",
                "disconnected_at": "1970-01-01T08:00:00+08:00"
            }
        ]
    }
}
Get Session By ID

Request:

GET /session/:id

Response:

{
    "code": 0,
    "message": "",
    "data": {
        "client_id": "id",
        "status": "online",
        "clean_session": false,
        "subscriptions": 0,
        "max_inflight": 32,
        "inflight_len": 0,
        "max_msg_queue": 1000,
        "msg_queue_len": 0,
        "max_await_rel": 100,
        "await_rel_len": 0,
        "msg_dropped_total": 0,
        "msg_delivered_total": 0,
        "connected_at": "2019-08-10T23:29:56+08:00",
        "disconnected_at": "1970-01-01T08:00:00+08:00"
    }
}
Get Subscriptions of the Client By ID

Request:

GET /subscriptions/:clientid?page=xxx&page_size=xxx
page: default to 1
page_size: default to 20

Response:

{
    "code": 0,
    "message": "",
    "data": [
        {
            "client_id": "id",
            "qos": 1,
            "name": "test1",
            "at": "2019-08-10T23:36:53.7859575+08:00"
        },
        {
            "client_id": "id",
            "qos": 0,
            "name": "test2",
            "at": "2019-08-10T23:36:53.7859575+08:00"
        }
    ]
}
Publish

Request:

POST /publish

Post Form:

qos : qos level
topic : topic name
payload : payload
retain: retain flag, retain != ""  means this is a retained message

Response:

{
    "code": 0,
    "message": "",
    "data": {}
}
Subscribe

Request:

POST /subscribe

Post Form:

qos : qos level
topic : topic filter
clientID : client id

Response:

{
    "code": 0,
    "message": "",
    "data": {}
}
UnSubscribe

Request:

POST /unsubscribe

Post Form:

topic : topic name
clientID : client id

Response:

{
    "code": 0,
    "message": "",
    "data": {}
}
Close Client

Request

DELETE /client/:id

Response

{
    "code": 0,
    "message": "",
    "data": {}
}

Documentation

Index

Constants

View Source
const (
	Online  = "online"
	Offline = "offline"
)
View Source
const CodeErr = -1
View Source
const CodeOK = 0

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type ClientInfo

type ClientInfo struct {
	ClientID       string    `json:"client_id"`
	Username       string    `json:"username"`
	Password       string    `json:"password"`
	KeepAlive      uint16    `json:"keep_alive"`
	CleanSession   bool      `json:"clean_session"`
	WillFlag       bool      `json:"will_flag"`
	WillRetain     bool      `json:"will_retain"`
	WillQos        uint8     `json:"will_qos"`
	WillTopic      string    `json:"will_topic"`
	WillPayload    string    `json:"will_payload"`
	RemoteAddr     string    `json:"remote_addr"`
	LocalAddr      string    `json:"local_addr"`
	ConnectedAt    time.Time `json:"connected_at"`
	DisconnectedAt time.Time `json:"disconnected_at"`
}

ClientInfo represents the client information

type Management

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

func New

func New(addr string, user gin.Accounts) *Management

func (*Management) CloseClient

func (m *Management) CloseClient(c *gin.Context)

CloseClient is the handle function for "Delete /client/:id" which close the client specified by the id

func (*Management) GetClient

func (m *Management) GetClient(c *gin.Context)

GetSessions is the handle function for "/client/:id"

func (*Management) GetClients

func (m *Management) GetClients(c *gin.Context)

GetClients is the handle function for "/clients"

func (*Management) GetSession

func (m *Management) GetSession(c *gin.Context)

GetSessions is the handle function for "/session/:id"

func (*Management) GetSessions

func (m *Management) GetSessions(c *gin.Context)

GetSessions is the handle function for "/sessions"

func (*Management) GetSubscriptions

func (m *Management) GetSubscriptions(c *gin.Context)

GetSessions is the handle function for "/subscriptions/:clientID"

func (*Management) HookWrapper

func (m *Management) HookWrapper() mqtt.HookWrapper

func (*Management) Load

func (m *Management) Load(server mqtt.Server) error

func (*Management) Name

func (m *Management) Name() string

func (*Management) OnSessionCreatedWrapper

func (m *Management) OnSessionCreatedWrapper(created mqtt.OnSessionCreated) mqtt.OnSessionCreated

OnSessionCreatedWrapper store the client when session created

func (*Management) OnSessionResumedWrapper

func (m *Management) OnSessionResumedWrapper(resumed mqtt.OnSessionResumed) mqtt.OnSessionResumed

OnSessionResumedWrapper refresh the client when session resumed

func (*Management) OnSessionTerminatedWrapper

func (m *Management) OnSessionTerminatedWrapper(terminated mqtt.OnSessionTerminated) mqtt.OnSessionTerminated

OnSessionTerminated remove the client when session terminated

func (*Management) OnSubscribedWrapper

func (m *Management) OnSubscribedWrapper(subscribed mqtt.OnSubscribed) mqtt.OnSubscribed

OnSubscribedWrapper store the subscription

func (*Management) OnUnsubscribedWrapper

func (m *Management) OnUnsubscribedWrapper(unsubscribe mqtt.OnUnsubscribed) mqtt.OnUnsubscribed

OnUnsubscribedWrapper remove the subscription

func (*Management) Publish

func (m *Management) Publish(c *gin.Context)

Publish is the handle function for "/publish" which publish a message to the server

func (*Management) Subscribe

func (m *Management) Subscribe(c *gin.Context)

Subscribe is the handle function for "/subscribe" which make a subscription for a client

func (*Management) Unload

func (m *Management) Unload() error

func (*Management) Unsubscribe

func (m *Management) Unsubscribe(c *gin.Context)

Unsubscribe is the handle function for "/unsubscribe" which unsubscribe the topic for the client

type Pager

type Pager struct {
	Page     int `json:"page"`
	PageSize int `json:"page_size"`
	Count    int `json:"count"`
}

Pager

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

Response is the response for the api server

type SessionInfo

type SessionInfo struct {
	ClientID              string    `json:"client_id"`
	Status                string    `json:"status"`
	CleanSession          bool      `json:"clean_session"`
	Subscriptions         uint64    `json:"subscriptions"`
	MaxInflight           int       `json:"max_inflight"`
	InflightLen           uint64    `json:"inflight_len"`
	MaxMsgQueue           int       `json:"max_msg_queue"`
	MsgQueueLen           uint64    `json:"msg_queue_len"`
	MaxAwaitRel           int       `json:"max_await_rel"`
	AwaitRelLen           uint64    `json:"await_rel_len"`
	Qos0MsgDroppedTotal   uint64    `json:"qos0_msg_dropped_total"`
	Qos1MsgDroppedTotal   uint64    `json:"qos1_msg_dropped_total"`
	Qos2MsgDroppedTotal   uint64    `json:"qos2_msg_dropped_total"`
	Qos0MsgDeliveredTotal uint64    `json:"qos0_msg_delivered_total"`
	Qos1MsgDeliveredTotal uint64    `json:"qos1_msg_delivered_total"`
	Qos2MsgDeliveredTotal uint64    `json:"qos2_msg_delivered_total"`
	ConnectedAt           time.Time `json:"connected_at"`
	DisconnectedAt        time.Time `json:"disconnected_at"`
}

SessionInfo represents the session information

type SubscriptionInfo

type SubscriptionInfo struct {
	ClientID string    `json:"client_id"`
	Qos      uint8     `json:"qos"`
	Name     string    `json:"name"`
	At       time.Time `json:"at"`
}

SubscriptionInfo represents the subscription information

Jump to

Keyboard shortcuts

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