Documentation ¶
Index ¶
- type AuthenticateFunc
- type AuthorizePublishFunc
- type AuthorizeSubscribeFunc
- type Broker
- type Client
- type ConnectToken
- type DisconnectToken
- type ExchangeMessage
- type Exchanger
- type MessageIds
- type OnClientHeartbeatCB
- type OnClientOfflineCB
- type OnClientOnlineCB
- type PacketAndToken
- type PubSubExchanger
- type PublishToken
- type RPCExchanger
- type SubscribeToken
- type Token
- type UnsubscribeToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthenticateFunc ¶
AuthenticateFunc AuthorizePublishFunc AuthorizeSubscribeFunc callback functions for authentication and authorization
type AuthorizePublishFunc ¶
AuthorizePublishFunc callback functions for authentication and authorization
type AuthorizeSubscribeFunc ¶
AuthorizeSubscribeFunc callback functions for authentication and authorization
type Broker ¶
type Broker struct { // server address to listen Addr string // rabbit uri RabbitURI string // extend the broker to suport RPC. (WARNNING: NOT standard MQTT feature) SuportRPC bool // rabbitmq connection RabbitConnection *amqp.Connection // if use mqtts, set this TLSConfig *tls.Config // callbacks Authenticate AuthenticateFunc AuthorizePublish AuthorizePublishFunc AuthorizeSubscribe AuthorizeSubscribeFunc OnClientOnline OnClientOnlineCB OnClientOffline OnClientOfflineCB OnClientHeartbeat OnClientHeartbeatCB }
Broker is MQTT main service
func (*Broker) InitRabbitConn ¶
func (b *Broker) InitRabbitConn()
InitRabbitConn init rabbitmq connection.
func (*Broker) ListenAndServe ¶
func (b *Broker) ListenAndServe()
ListenAndServe serves for mqtt connections.
type Client ¶
type Client struct { Conn net.Conn Broker *Broker Identifier string LastHeartbeat time.Time KeepAliveInterval int Channel *amqp.Channel Exchangers map[string]Exchanger SubscribeTopics map[string]string // contains filtered or unexported fields }
Client a client servces an MQTT remote client connection
type ConnectToken ¶
type ConnectToken struct {
// contains filtered or unexported fields
}
ConnectToken is an extension of Token containing the extra fields required to provide information about calls to Connect()
func (*ConnectToken) ReturnCode ¶
func (c *ConnectToken) ReturnCode() byte
ReturnCode returns the acknowlegement code in the connack sent in response to a Connect()
func (*ConnectToken) Wait ¶
func (b *ConnectToken) Wait() bool
Wait will wait indefinitely for the Token to complete, ie the Publish to be sent and confirmed receipt from the broker
func (*ConnectToken) WaitTimeout ¶
WaitTimeout takes a time in ms to wait for the flow associated with the Token to complete, returns true if it returned before the timeout or returns false if the timeout occurred. In the case of a timeout the Token does not have an error set in case the caller wishes to wait again
type DisconnectToken ¶
type DisconnectToken struct {
// contains filtered or unexported fields
}
DisconnectToken is an extension of Token containing the extra fields required to provide information about calls to Disconnect()
func (*DisconnectToken) Wait ¶
func (b *DisconnectToken) Wait() bool
Wait will wait indefinitely for the Token to complete, ie the Publish to be sent and confirmed receipt from the broker
func (*DisconnectToken) WaitTimeout ¶
WaitTimeout takes a time in ms to wait for the flow associated with the Token to complete, returns true if it returned before the timeout or returns false if the timeout occurred. In the case of a timeout the Token does not have an error set in case the caller wishes to wait again
type ExchangeMessage ¶
ExchangeMessage is a message in exchange
type Exchanger ¶
type Exchanger interface { // init the exchanger Init() error // publish a message. Publish(ExchangeMessage) error // subsctibe a topic and return a channel to receive message. Subscribe(topic string) (chan ExchangeMessage, error) // unsubstring a topic Unsubscribe(topic string) error }
Exchanger is an interface for handling pub/sub messages
type MessageIds ¶
MessageIds is 16 bit message id as specified by the MQTT spec. In general, these values should not be depended upon by the client application.
type OnClientHeartbeatCB ¶
type OnClientHeartbeatCB func(client *Client)
OnClientHeartbeatCB callback function when receive a client heartbeat
type OnClientOfflineCB ¶
type OnClientOfflineCB func(client *Client)
OnClientOfflineCB callback function when losing heartbeat from client
type OnClientOnlineCB ¶
type OnClientOnlineCB func(client *Client)
OnClientOnlineCB callback function when client connect success
type PacketAndToken ¶
type PacketAndToken struct {
// contains filtered or unexported fields
}
PacketAndToken is a struct that contains both a ControlPacket and a Token. This struct is passed via channels between the client interface code and the underlying code responsible for sending and receiving MQTT messages.
type PubSubExchanger ¶
type PubSubExchanger struct { TopicQueue map[string]string TopicChan map[string]chan ExchangeMessage MessageIds MessageIds Channel *amqp.Channel }
PubSubExchanger is the exchange in RabbitMQ for publish & subscribe.
func NewPubSubExchanger ¶
func NewPubSubExchanger(channel *amqp.Channel) *PubSubExchanger
NewPubSubExchanger creates a new exchange for pubsub.
func (*PubSubExchanger) Publish ¶
func (pubsub *PubSubExchanger) Publish(msg ExchangeMessage) error
Publish a massage
func (*PubSubExchanger) Subscribe ¶
func (pubsub *PubSubExchanger) Subscribe(topic string) (chan ExchangeMessage, error)
Subscribe topic
func (*PubSubExchanger) Unsubscribe ¶
func (pubsub *PubSubExchanger) Unsubscribe(topic string) error
Unsubscribe topic
type PublishToken ¶
type PublishToken struct {
// contains filtered or unexported fields
}
PublishToken is an extension of Token containing the extra fields required to provide information about calls to Publish()
func (*PublishToken) MessageID ¶
func (p *PublishToken) MessageID() uint16
MessageID returns the MQTT message ID that was assigned to the Publish packet when it was sent to the broker
func (*PublishToken) Wait ¶
func (b *PublishToken) Wait() bool
Wait will wait indefinitely for the Token to complete, ie the Publish to be sent and confirmed receipt from the broker
func (*PublishToken) WaitTimeout ¶
WaitTimeout takes a time in ms to wait for the flow associated with the Token to complete, returns true if it returned before the timeout or returns false if the timeout occurred. In the case of a timeout the Token does not have an error set in case the caller wishes to wait again
type RPCExchanger ¶
type RPCExchanger struct { Channel *amqp.Channel RPCQueues map[string]string RPCCorrelationID map[string]string MsgChan map[string]chan ExchangeMessage }
RPCExchanger is the exchange in RabbitMQ for rpcs.
func NewPRCExchanger ¶
func NewPRCExchanger(channel *amqp.Channel) *RPCExchanger
NewPRCExchanger creates a new rpc exchanger.
func (*RPCExchanger) Publish ¶
func (rpc *RPCExchanger) Publish(msg ExchangeMessage) error
Publish send a rpc request or response
func (*RPCExchanger) Subscribe ¶
func (rpc *RPCExchanger) Subscribe(topic string) (chan ExchangeMessage, error)
Subscribe waits for prc request or response.
func (*RPCExchanger) Unsubscribe ¶
func (rpc *RPCExchanger) Unsubscribe(topic string) error
Unsubscribe rpc topic.
type SubscribeToken ¶
type SubscribeToken struct {
// contains filtered or unexported fields
}
SubscribeToken is an extension of Token containing the extra fields required to provide information about calls to Subscribe()
func (*SubscribeToken) Result ¶
func (s *SubscribeToken) Result() map[string]byte
Result returns a map of topics that were subscribed to along with the matching return code from the broker. This is either the Qos value of the subscription or an error code.
func (*SubscribeToken) Wait ¶
func (b *SubscribeToken) Wait() bool
Wait will wait indefinitely for the Token to complete, ie the Publish to be sent and confirmed receipt from the broker
func (*SubscribeToken) WaitTimeout ¶
WaitTimeout takes a time in ms to wait for the flow associated with the Token to complete, returns true if it returned before the timeout or returns false if the timeout occurred. In the case of a timeout the Token does not have an error set in case the caller wishes to wait again
type Token ¶
type Token interface { Wait() bool WaitTimeout(time.Duration) bool Error() error // contains filtered or unexported methods }
Token defines the interface for the tokens used to indicate when actions have completed.
type UnsubscribeToken ¶
type UnsubscribeToken struct {
// contains filtered or unexported fields
}
UnsubscribeToken is an extension of Token containing the extra fields required to provide information about calls to Unsubscribe()
func (*UnsubscribeToken) Wait ¶
func (b *UnsubscribeToken) Wait() bool
Wait will wait indefinitely for the Token to complete, ie the Publish to be sent and confirmed receipt from the broker
func (*UnsubscribeToken) WaitTimeout ¶
WaitTimeout takes a time in ms to wait for the flow associated with the Token to complete, returns true if it returned before the timeout or returns false if the timeout occurred. In the case of a timeout the Token does not have an error set in case the caller wishes to wait again