Class: Paho::ConnectOptions

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/paho/connect_options.rb

Constant Summary collapse

DEFAULT_CLEAN_SESSION =
true
DEFAULT_CONNECTION_TIMEOUT =
30
DEFAULT_KEEP_ALIVE_INTERVAL =
60
DEFAULT_MQTT_VERSION =
0
MQTT_VERSION_3_1 =
3
MQTT_VERSION_3_1_1 =
4

Instance Method Summary collapse

Constructor Details

#initializeConnectOptions

Returns a new instance of ConnectOptions.


25
26
27
# File 'lib/paho/connect_options.rb', line 25

def initialize
  @options = Paho::Eclipse::MqttConnectOptions.new
end

Instance Method Details

#clean_session=(val) ⇒ Object

Sets whether the client and server should remember state across restarts and reconnects.

If set to false both the client and server will maintain state across restarts of the client, the server and the connection. As state is maintained:

  • Message delivery will be reliable meeting the specified QOS even if the client, server or connection are restarted.

  • The server will treat a subscription as durable.

If set to true the client and server will not maintain state across restarts of the client, the server or the connection. This means

  • Message delivery to the specified QOS cannot be maintained if the client, server or connection are restarted

  • The server will treat a subscription as non-durable

Parameters:

  • val (Boolean)

    value of the clean session


43
44
45
# File 'lib/paho/connect_options.rb', line 43

def clean_session=(val)
  @options.setCleanSession(val)
end

#connection_timeout=(val) ⇒ Object

Sets the connection timeout value. This value, measured in seconds, defines the maximum time interval the client will wait for the network connection to the MQTT server to be established. The default timeout is 30 seconds. A value of 0 disables timeout processing meaning the client will wait until the network connection is made successfully or fails.


64
65
66
# File 'lib/paho/connect_options.rb', line 64

def connection_timeout=(val)
  @options.setConnectionTimeout(val)
end

#keep_alive_interval=(val) ⇒ Object

Sets the “keep alive” interval. This value, measured in seconds, defines the maximum time interval between messages sent or received. It enables the client to detect if the server is no longer available, without having to wait for the TCP/IP timeout. The client will ensure that at least one message travels across the network within each keep alive period. In the absence of a data-related message during the time period, the client sends a very small “ping” message, which the server will acknowledge. A value of 0 disables keepalive processing in the client.


55
56
57
# File 'lib/paho/connect_options.rb', line 55

def keep_alive_interval=(val)
  @options.setKeepAliveInterval(val)
end

#password=(val) ⇒ Object

Sets the password to use for the connection.


69
70
71
# File 'lib/paho/connect_options.rb', line 69

def password=(val)
  @options.setPassword(val)
end

#server_urisObject


78
79
80
81
82
# File 'lib/paho/connect_options.rb', line 78

def server_uris
  # Forwarding this to Java will yield a java.lang.String[] which might
  # not be expected.
  @options.getServerURIs.map(&:to_s)
end

#server_uris=(val) ⇒ Object

Set a list of one or more serverURIs the client may connect to.

Each serverURI specifies the address of a server that the client may connect to. Two types of connection are supported tcp:// for a TCP connection and `ssl://` for a TCP connection secured by SSL/TLS. For example:

  • tcp://localhost:1883

  • ssl://localhost:8883

If the port is not specified, it will default to 1883 for tcp://“ URIs, and 8883 for ssl:// URIs.

If serverURIs is set then it overrides the serverURI parameter passed in on the constructor of the MQTT client.

When an attempt to connect is initiated the client will start with the first serverURI in the list and work through the list until a connection is established with a server. If a connection cannot be made to any of the servers then the connect attempt fails.

Specifying a list of servers that a client may connect to has several uses:

  1. High Availability and reliable message delivery Some MQTT servers support a high availability feature where two or more “equal” MQTT servers share state. An MQTT client can connect to any of the “equal” servers and be assured that messages are reliably delivered and durable subscriptions are maintained no matter which server the client connects to. The cleansession flag must be set to false if durable subscriptions and/or reliable message delivery is required.

  2. Hunt List A set of servers may be specified that are not “equal” (as in the high availability option). As no state is shared across the servers reliable message delivery and durable subscriptions are not valid. The cleansession flag must be set to true if the hunt list mode is used


111
112
113
# File 'lib/paho/connect_options.rb', line 111

def server_uris=(val)
  @options.setServerURIs(val)
end

#username=(val) ⇒ Object

Sets the user name to use for the connection.


74
75
76
# File 'lib/paho/connect_options.rb', line 74

def username=(val)
  @options.setUserName(val)
end