connect

package
Version: v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IMqttMessageListener added in v1.0.2

type IMqttMessageListener interface {
	OnMessage(message mqtt.Message)
}

type MqttConnection added in v1.0.2

type MqttConnection struct {

	// The logger.
	Logger *clog.CompositeLogger
	// The connection resolver.
	ConnectionResolver *MqttConnectionResolver
	// The configuration options.
	Options *cconf.ConfigParams

	// The MQTT connection object.
	Connection mqtt.Client
	// contains filtered or unexported fields
}

*

MQTT connection using plain driver.
By defining a connection and sharing it through multiple message queues
you can reduce number of used connections.

### Configuration parameters ###
 - client_id:               (optional) name of the client id
 - connection(s):
   - discovery_key:               (optional) a key to retrieve the connection from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/connect.idiscovery.html IDiscovery]]
   - host:                        host name or IP address
   - port:                        port number
   - uri:                         resource URI or connection string with all parameters in it
 - credential(s):
   - store_key:                   (optional) a key to retrieve the credentials from [[https://pip-services3-node.github.io/pip-services3-components-node/interfaces/auth.icredentialstore.html ICredentialStore]]
   - username:                    user name
   - password:                    user password
 - options:
   - retry_connect:        (optional) turns on/off automated reconnect when connection is log (default: true)
   - connect_timeout:      (optional) number of milliseconds to wait for connection (default: 30000)
   - reconnect_timeout:    (optional) number of milliseconds to wait on each reconnection attempt (default: 1000)
   - keepalive_timeout:    (optional) number of milliseconds to ping broker while inactive (default: 3000)

### References ###

  • \*:logger:\*:\*:1.0 (optional) ILogger components to pass log messages
  • \*:discovery:\*:\*:1.0 (optional) IDiscovery services
  • \*:credential-store:\*:\*:1.0 (optional) Credential stores to resolve credentials

func NewMqttConnection added in v1.0.2

func NewMqttConnection() *MqttConnection

NewMqttConnection creates a new instance of the connection component.

func (*MqttConnection) Close added in v1.0.2

func (c *MqttConnection) Close(correlationId string) error

Closes component and frees used resources.

  • correlationId (optional) transaction id to trace execution through call chain.

Return error or nil no errors occured

func (*MqttConnection) Configure added in v1.0.2

func (c *MqttConnection) Configure(config *cconf.ConfigParams)

Configures component by passing configuration parameters.

  • config configuration parameters to be set.

func (*MqttConnection) CreateQueue added in v1.0.4

func (c *MqttConnection) CreateQueue() error

func (*MqttConnection) DeleteQueue added in v1.0.4

func (c *MqttConnection) DeleteQueue() error

func (*MqttConnection) GetConnection added in v1.0.2

func (c *MqttConnection) GetConnection() mqtt.Client

func (*MqttConnection) IsOpen added in v1.0.2

func (c *MqttConnection) IsOpen() bool

Checks if the component is opened. Returns true if the component has been opened and false otherwise.

func (*MqttConnection) Open added in v1.0.2

func (c *MqttConnection) Open(correlationId string) error

Opens the component.

  • correlationId (optional) transaction id to trace execution through call chain.
  • Return error or nil no errors occured.

func (*MqttConnection) Publish added in v1.0.2

func (c *MqttConnection) Publish(topic string, qos byte, retained bool, data []byte) error

Publish a message to a specified topic

Parameters:

  • topic a topic name
  • qos quality of service (QOS) for the message
  • retained retained flag for the message
  • data a message to be published

Returns: error or nil for success

func (*MqttConnection) ReadQueueNames added in v1.0.4

func (c *MqttConnection) ReadQueueNames() ([]string, error)

func (*MqttConnection) SetReferences added in v1.0.2

func (c *MqttConnection) SetReferences(references cref.IReferences)

Sets references to dependent components.

  • references references to locate the component dependencies.

func (*MqttConnection) Subscribe added in v1.0.2

func (c *MqttConnection) Subscribe(topic string, qos byte, listener IMqttMessageListener) error

Subscribe to a topic

Parameters:

  • topic a topic name
  • qos quality of service (QOS) for the subscription
  • listener a message listener

Returns: err or nil for success

func (*MqttConnection) Unsubscribe added in v1.0.2

func (c *MqttConnection) Unsubscribe(topic string, listener IMqttMessageListener) error

Unsubscribe from a previously subscribed topic topic

Parameters:

  • topic a topic name
  • qos quality of service (QOS) for the subscription
  • listener a message listener

Returns: err or nil for success

type MqttConnectionResolver

type MqttConnectionResolver struct {
	ConnectionResolver *ccon.ConnectionResolver
	CredentialResolver *cauth.CredentialResolver
}

MqttConnectionResolver helper class that resolves Mqtt connection and credential parameters, validates them and generates connection options.

Configuration parameters:

- connection(s):

  • discovery_key: (optional) a key to retrieve the connection from IDiscovery
  • host: host name or IP address
  • port: port number
  • uri: resource URI or connection string with all parameters in it

- credential(s):

  • store_key: (optional) a key to retrieve the credentials from ICredentialStore

  • username: user name

  • password: user password

    References:

- *:discovery:*:*:1.0 (optional) IDiscovery services to resolve connections - *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials

func NewMqttConnectionResolver

func NewMqttConnectionResolver() *MqttConnectionResolver

func (*MqttConnectionResolver) Compose

func (c *MqttConnectionResolver) Compose(correlationId string, connections []*ccon.ConnectionParams,
	credential *cauth.CredentialParams) (*cconf.ConfigParams, error)

Compose method are composes Mqtt connection options from connection and credential parameters. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.
  • connection *ccon.ConnectionParams connection parameters
  • credential *cauth.CredentialParams credential parameters

Returns: options *cconf.ConfigParams, err error resolved options or error.

func (*MqttConnectionResolver) Configure

func (c *MqttConnectionResolver) Configure(config *cconf.ConfigParams)

Configure are configures component by passing configuration parameters. Parameters:

  • config *cconf.ConfigParams

configuration parameters to be set.

func (*MqttConnectionResolver) Resolve

func (c *MqttConnectionResolver) Resolve(correlationId string) (*cconf.ConfigParams, error)

Resolves MQTT connection options from connection and credential parameters. Parameters:

  • correlationId string (optional) transaction id to trace execution through call chain.

Returns options *cconf.ConfigParams, err error receives resolved options or error.

func (*MqttConnectionResolver) SetReferences

func (c *MqttConnectionResolver) SetReferences(references cref.IReferences)

SetReferences are sets references to dependent components. Parameters:

  • references cref.IReferences references to locate the component dependencies.

type MqttSubscription added in v1.0.2

type MqttSubscription struct {
	Topic    string
	Qos      byte
	Listener IMqttMessageListener
	Skip     int32
}

Jump to

Keyboard shortcuts

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