Documentation ¶
Index ¶
- Variables
- type Client
- type Configuration
- func (cfg *Configuration) AcknowledgeTimeout() time.Duration
- func (cfg *Configuration) Broker() string
- func (cfg *Configuration) ConnectHandler() ConnectHandler
- func (cfg *Configuration) ConnectTimeout() time.Duration
- func (cfg *Configuration) ConnectionLostHandler() ConnectionLostHandler
- func (cfg *Configuration) Credentials() *Credentials
- func (cfg *Configuration) DisconnectTimeout() time.Duration
- func (cfg *Configuration) KeepAlive() time.Duration
- func (cfg *Configuration) SubscribeTimeout() time.Duration
- func (cfg *Configuration) TLSConfig() *tls.Config
- func (cfg *Configuration) UnsubscribeTimeout() time.Duration
- func (cfg *Configuration) WithAcknowledgeTimeout(acknowledgeTimeout time.Duration) *Configuration
- func (cfg *Configuration) WithBroker(broker string) *Configuration
- func (cfg *Configuration) WithConnectHandler(connectHandler ConnectHandler) *Configuration
- func (cfg *Configuration) WithConnectTimeout(connectTimeout time.Duration) *Configuration
- func (cfg *Configuration) WithConnectionLostHandler(connectionLostHandler ConnectionLostHandler) *Configuration
- func (cfg *Configuration) WithCredentials(credentials *Credentials) *Configuration
- func (cfg *Configuration) WithDisconnectTimeout(disconnectTimeout time.Duration) *Configuration
- func (cfg *Configuration) WithKeepAlive(keepAlive time.Duration) *Configuration
- func (cfg *Configuration) WithSubscribeTimeout(subscribeTimeout time.Duration) *Configuration
- func (cfg *Configuration) WithTLSConfig(tlsConfig *tls.Config) *Configuration
- func (cfg *Configuration) WithUnsubscribeTimeout(unsubscribeTimeout time.Duration) *Configuration
- type ConnectHandler
- type ConnectionLostHandler
- type Credentials
- type Handler
- type Logger
- type LoggerStub
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAcknowledgeTimeout is an error that acknowledgement is not received within the timeout. ErrAcknowledgeTimeout = errors.New("acknowledge timeout") // ErrSubscribeTimeout is an error that subscription confirmation is not received within the timeout. ErrSubscribeTimeout = errors.New("subscribe timeout") // ErrUnsubscribeTimeout is an error that unsubscription confirmation is not received within the timeout. ErrUnsubscribeTimeout = errors.New("unsubscribe timeout") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { // Connect connects the client to the configured Ditto endpoint provided via the Client's Configuration at creation time. // If any error occurs during the connection's initiation - it's returned here. // An actual connection status is callbacked to the provided ConnectHandler // as soon as the connection is established and all Client's internal preparations are performed. // If the connection gets lost during runtime - the ConnectionLostHandler is notified to handle the case. Connect() error // Disconnect disconnects the client from the configured Ditto endpoint. Disconnect() // Reply is an auxiliary method to send replies for specific requestIDs if such has been provided along with the incoming protocol.Envelope. // The requestID must be the same as the one provided with the request protocol.Envelope. // An error is returned if the reply could not be sent for some reason. Reply(requestID string, message *protocol.Envelope) error // Send sends a protocol.Envelope to the Client's configured Ditto endpoint. // An error is returned if the envelope could not be sent for some reason. Send(message *protocol.Envelope) error // Subscribe ensures that all incoming Ditto messages will be transferred to the provided Handlers. Subscribe(handlers ...Handler) // Unsubscribe cancels sending incoming Ditto messages from the client to the provided Handlers // and removes them from the subscriptions list of the client. // If Unsubscribe is called without arguments, it will cancel and remove all currently subscribed Handlers. Unsubscribe(handlers ...Handler) }
Client is the Ditto's library main interface definition. The interface is intended to abstract multiple implementations over different transports. Client has connect/disconnect capabilities along with the options to subscribe/unsubscribe for receiving all Ditto messages being exchanged using the underlying transport.
func NewClient ¶
func NewClient(cfg *Configuration) Client
NewClient creates a new Client instance with the provided Configuration.
func NewClientMQTT ¶
func NewClientMQTT(mqttClient MQTT.Client, cfg *Configuration) (Client, error)
NewClientMQTT creates a new Client instance with the Configuration, if such is provided, that is going to use the external MQTT client.
It is expected that the provided MQTT client is already connected. So this Client must be controlled from outside and its Connect/Disconnect methods must be invoked accordingly.
If a Configuration is provided it may include ConnectHandler and ConnectionLostHandler, as well as acknowledge, subscribe and unsubscribe timeout. As an external MQTT client is used, other fields are not needed and regarded as invalid ones.
Returns an error if the provided MQTT client is not connected or the Configuration contains invalid fields.
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration provides the Client's configuration.
func NewConfiguration ¶
func NewConfiguration() *Configuration
NewConfiguration creates a new Configuration instance.
func (*Configuration) AcknowledgeTimeout ¶
func (cfg *Configuration) AcknowledgeTimeout() time.Duration
AcknowledgeTimeout provides the timeout to wait for confirmation that a MQTT message is delivered to the broker. The default is 15 seconds.
func (*Configuration) Broker ¶
func (cfg *Configuration) Broker() string
Broker provides the current MQTT broker the client is to connect to.
func (*Configuration) ConnectHandler ¶
func (cfg *Configuration) ConnectHandler() ConnectHandler
ConnectHandler provides the currently configured ConnectHandler.
func (*Configuration) ConnectTimeout ¶
func (cfg *Configuration) ConnectTimeout() time.Duration
ConnectTimeout provides the timeout for connecting the client. The default is 30 seconds.
func (*Configuration) ConnectionLostHandler ¶
func (cfg *Configuration) ConnectionLostHandler() ConnectionLostHandler
ConnectionLostHandler provides the currently configured ConnectionLostHandler.
func (*Configuration) Credentials ¶
func (cfg *Configuration) Credentials() *Credentials
Credentials provides the currently configured authentication credentials used for the underlying connection.
func (*Configuration) DisconnectTimeout ¶
func (cfg *Configuration) DisconnectTimeout() time.Duration
DisconnectTimeout provides the timeout for disconnecting the client. The default is 250 milliseconds.
func (*Configuration) KeepAlive ¶
func (cfg *Configuration) KeepAlive() time.Duration
KeepAlive provides the keep alive connection's period. The default is 30 seconds.
func (*Configuration) SubscribeTimeout ¶
func (cfg *Configuration) SubscribeTimeout() time.Duration
SubscribeTimeout provides the timeout to wait for successful MQTT subscription. The default is 15 seconds.
func (*Configuration) TLSConfig ¶
func (cfg *Configuration) TLSConfig() *tls.Config
TLSConfig provides the current TLS configuration for the underlying connection.
func (*Configuration) UnsubscribeTimeout ¶
func (cfg *Configuration) UnsubscribeTimeout() time.Duration
UnsubscribeTimeout provides the timeout to wait for successful MQTT unsubscription. The default is 5 seconds.
func (*Configuration) WithAcknowledgeTimeout ¶
func (cfg *Configuration) WithAcknowledgeTimeout(acknowledgeTimeout time.Duration) *Configuration
WithAcknowledgeTimeout configures the timeout for acknowledgement of the Client.
func (*Configuration) WithBroker ¶
func (cfg *Configuration) WithBroker(broker string) *Configuration
WithBroker configures the MQTT's broker the Client to connect to.
func (*Configuration) WithConnectHandler ¶
func (cfg *Configuration) WithConnectHandler(connectHandler ConnectHandler) *Configuration
WithConnectHandler configures the connectHandler to be notified when the Client's connection is established.
func (*Configuration) WithConnectTimeout ¶
func (cfg *Configuration) WithConnectTimeout(connectTimeout time.Duration) *Configuration
WithConnectTimeout configures the timeout for connection of the Client.
func (*Configuration) WithConnectionLostHandler ¶
func (cfg *Configuration) WithConnectionLostHandler(connectionLostHandler ConnectionLostHandler) *Configuration
WithConnectionLostHandler configures the connectionLostHandler to be notified is the Client's connection gets lost during runtime.
func (*Configuration) WithCredentials ¶
func (cfg *Configuration) WithCredentials(credentials *Credentials) *Configuration
WithCredentials configures the credentials to be used for authentication by the underlying connection of the Client.
func (*Configuration) WithDisconnectTimeout ¶
func (cfg *Configuration) WithDisconnectTimeout(disconnectTimeout time.Duration) *Configuration
WithDisconnectTimeout configures the timeout for disconnection of the Client.
func (*Configuration) WithKeepAlive ¶
func (cfg *Configuration) WithKeepAlive(keepAlive time.Duration) *Configuration
WithKeepAlive configures the keep alive time period for the underlying Client's connection.
func (*Configuration) WithSubscribeTimeout ¶
func (cfg *Configuration) WithSubscribeTimeout(subscribeTimeout time.Duration) *Configuration
WithSubscribeTimeout configures the timeout for subscription of the Client.
func (*Configuration) WithTLSConfig ¶
func (cfg *Configuration) WithTLSConfig(tlsConfig *tls.Config) *Configuration
WithTLSConfig sets the TLS configuration to be used by the Client's underlying connection.
func (*Configuration) WithUnsubscribeTimeout ¶
func (cfg *Configuration) WithUnsubscribeTimeout(unsubscribeTimeout time.Duration) *Configuration
WithUnsubscribeTimeout configures the timeout for unsubscription of the Client.
type ConnectHandler ¶
type ConnectHandler func(client Client)
ConnectHandler is called when a successful connection to the configured Ditto endpoint is established and all Client's internal preparations are done.
type ConnectionLostHandler ¶
ConnectionLostHandler is called is the connection is lost during runtime.
type Credentials ¶
Credentials represents a user credentials for authentication used by the underlying connection (e.g. MQTT).
type Handler ¶
Handler represents a callback handler that is called on each received message. If the underlying transport provides a special requestID related to the Envelope, it's also provided to the handler so that chained responses to the ID can be later sent properly.
type Logger ¶
type Logger interface { Println(v ...interface{}) Printf(format string, v ...interface{}) }
Logger interface allows plugging of a logger implementation that fits best the needs of the application that is to use the Ditto library.
var ( INFO Logger = LoggerStub{} WARN Logger = LoggerStub{} DEBUG Logger = LoggerStub{} ERROR Logger = LoggerStub{} )
Levels of the library's output that can be configured during package initialization in init().
type LoggerStub ¶
type LoggerStub struct{}
LoggerStub provides an empty default implementation.
func (LoggerStub) Printf ¶
func (LoggerStub) Printf(format string, v ...interface{})
Printf provides an empty default implementation for formatted logging.
func (LoggerStub) Println ¶
func (LoggerStub) Println(v ...interface{})
Println provides an empty default implementation for logging.