Class: VertxMqtt::MqttClient

Inherits:
Object
  • Object
show all
Defined in:
/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb

Overview

An MQTT client

Constant Summary

@@j_api_type =
Object.new

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


22
23
24
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 22

def @@j_api_type.accept?(obj)
  obj.class == MqttClient
end

+ (::VertxMqtt::MqttClient) create(vertx = nil, options = nil)

Return an MQTT client instance

Parameters:

  • vertx (::Vertx::Vertx) (defaults to: nil)
    Vert.x instance
  • options (Hash) (defaults to: nil)
    MQTT client options

Returns:

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 41

def self.create(vertx=nil,options=nil)
  if vertx.class.method_defined?(:j_del) && !block_given? && options == nil
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxMqtt::MqttClient.java_method(:create, [Java::IoVertxCore::Vertx.java_class]).call(vertx.j_del),::VertxMqtt::MqttClient)
  elsif vertx.class.method_defined?(:j_del) && options.class == Hash && !block_given?
    return ::Vertx::Util::Utils.safe_create(Java::IoVertxMqtt::MqttClient.java_method(:create, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxMqtt::MqttClientOptions.java_class]).call(vertx.j_del,Java::IoVertxMqtt::MqttClientOptions.new(::Vertx::Util::Utils.to_json_object(options))),::VertxMqtt::MqttClient)
  end
  raise ArgumentError, "Invalid arguments when calling create(#{vertx},#{options})"
end

+ (Object) j_api_type



31
32
33
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 31

def self.j_api_type
  @@j_api_type
end

+ (Object) j_class



34
35
36
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 34

def self.j_class
  Java::IoVertxMqtt::MqttClient.java_class
end

+ (Object) unwrap(obj)



28
29
30
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 28

def @@j_api_type.unwrap(obj)
  obj.j_del
end

+ (Object) wrap(obj)



25
26
27
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 25

def @@j_api_type.wrap(obj)
  MqttClient.new(obj)
end

Instance Method Details

- (String) client_id

Returns the client identifier

Returns:

  • (String)
    the client identifier

Raises:

  • (ArgumentError)


262
263
264
265
266
267
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 262

def client_id
  if !block_given?
    return @j_del.java_method(:clientId, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling client_id()"
end

- (self) close_handler { ... }

Set a handler that will be called when the connection with server is closed

Yields:

  • handler to call

Returns:

  • (self)

Raises:

  • (ArgumentError)


244
245
246
247
248
249
250
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 244

def close_handler
  if block_given?
    @j_del.java_method(:closeHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
    return self
  end
  raise ArgumentError, "Invalid arguments when calling close_handler()"
end

- (self) connect(port = nil, host = nil, serverName = nil) { ... }

Connects to an MQTT server calling connectHandler after connection

Parameters:

  • port (Fixnum) (defaults to: nil)
    port of the MQTT server
  • host (String) (defaults to: nil)
    hostname/ip address of the MQTT server
  • serverName (String) (defaults to: nil)
    the SNI server name

Yields:

  • handler called when the asynchronous connect call ends

Returns:

  • (self)

Raises:

  • (ArgumentError)


55
56
57
58
59
60
61
62
63
64
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 55

def connect(port=nil,host=nil,serverName=nil)
  if port.class == Fixnum && host.class == String && block_given? && serverName == nil
    @j_del.java_method(:connect, [Java::int.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(port,host,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttConnAckMessage) : nil) }))
    return self
  elsif port.class == Fixnum && host.class == String && serverName.class == String && block_given?
    @j_del.java_method(:connect, [Java::int.java_class,Java::java.lang.String.java_class,Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(port,host,serverName,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ::Vertx::Util::Utils.safe_create(ar.result,::VertxMqtt::MqttConnAckMessage) : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling connect(#{port},#{host},#{serverName})"
end

- (true, false) connected?

Returns if the connection between client and remote server is established/open

Returns:

  • (true, false)
    if the connection between client and remote server is established/open

Raises:

  • (ArgumentError)


269
270
271
272
273
274
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 269

def connected?
  if !block_given?
    return @j_del.java_method(:isConnected, []).call()
  end
  raise ArgumentError, "Invalid arguments when calling connected?()"
end

- (self) disconnect { ... }

Disconnects from the MQTT server calling disconnectHandler after disconnection

Yields:

  • handler called when asynchronous disconnect call ends

Returns:

  • (self)

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
75
76
77
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 68

def disconnect
  if !block_given?
    @j_del.java_method(:disconnect, []).call()
    return self
  elsif block_given?
    @j_del.java_method(:disconnect, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling disconnect()"
end

- (self) exception_handler { ... }

Set an exception handler for the client, that will be called when an error happens in internal netty structures. io.netty.handler.codec.DecoderException can be one of the cause

Yields:

  • the exception handler

Returns:

  • (self)

Raises:

  • (ArgumentError)


234
235
236
237
238
239
240
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 234

def exception_handler
  if block_given?
    @j_del.java_method(:exceptionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.from_throwable(event)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling exception_handler()"
end

- (self) ping

This method is needed by the client in order to avoid server closes the connection due to the keep alive timeout if client has no messages to send

Returns:

  • (self)

Raises:

  • (ArgumentError)


254
255
256
257
258
259
260
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 254

def ping
  if !block_given?
    @j_del.java_method(:ping, []).call()
    return self
  end
  raise ArgumentError, "Invalid arguments when calling ping()"
end

- (self) ping_response_handler { ... }

Sets handler which will be called after PINGRESP packet receiving

Yields:

  • handler to call

Returns:

  • (self)

Raises:

  • (ArgumentError)


221
222
223
224
225
226
227
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 221

def ping_response_handler
  if block_given?
    @j_del.java_method(:pingResponseHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield })
    return self
  end
  raise ArgumentError, "Invalid arguments when calling ping_response_handler()"
end

- (self) publish(topic = nil, payload = nil, qosLevel = nil, isDup = nil, isRetain = nil) { ... }

Sends the PUBLISH message to the remote MQTT server

Parameters:

  • topic (String) (defaults to: nil)
    topic on which the message is published
  • payload (::Vertx::Buffer) (defaults to: nil)
    message payload
  • qosLevel (:AT_MOST_ONCE, :AT_LEAST_ONCE, :EXACTLY_ONCE, :FAILURE) (defaults to: nil)
    QoS level
  • isDup (true, false) (defaults to: nil)
    if the message is a duplicate
  • isRetain (true, false) (defaults to: nil)
    if the message needs to be retained

Yields:

  • handler called after PUBLISH packet sent with packetid (not when QoS 0)

Returns:

  • (self)

Raises:

  • (ArgumentError)


86
87
88
89
90
91
92
93
94
95
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 86

def publish(topic=nil,payload=nil,qosLevel=nil,isDup=nil,isRetain=nil)
  if topic.class == String && payload.class.method_defined?(:j_del) && qosLevel.class == Symbol && (isDup.class == TrueClass || isDup.class == FalseClass) && (isRetain.class == TrueClass || isRetain.class == FalseClass) && !block_given?
    @j_del.java_method(:publish, [Java::java.lang.String.java_class,Java::IoVertxCoreBuffer::Buffer.java_class,Java::IoNettyHandlerCodecMqtt::MqttQoS.java_class,Java::boolean.java_class,Java::boolean.java_class]).call(topic,payload.j_del,Java::IoNettyHandlerCodecMqtt::MqttQoS.valueOf(qosLevel.to_s),isDup,isRetain)
    return self
  elsif topic.class == String && payload.class.method_defined?(:j_del) && qosLevel.class == Symbol && (isDup.class == TrueClass || isDup.class == FalseClass) && (isRetain.class == TrueClass || isRetain.class == FalseClass) && block_given?
    @j_del.java_method(:publish, [Java::java.lang.String.java_class,Java::IoVertxCoreBuffer::Buffer.java_class,Java::IoNettyHandlerCodecMqtt::MqttQoS.java_class,Java::boolean.java_class,Java::boolean.java_class,Java::IoVertxCore::Handler.java_class]).call(topic,payload.j_del,Java::IoNettyHandlerCodecMqtt::MqttQoS.valueOf(qosLevel.to_s),isDup,isRetain,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling publish(#{topic},#{payload},#{qosLevel},#{isDup},#{isRetain})"
end

- (self) publish_completion_expiration_handler { ... }

Sets a handler which will be called when the client does not receive a PUBACK or PUBREC/PUBCOMP for a message published using QoS 1 or 2 respectively.

The time to wait for an acknowledgement message can be configured using Hash#set_ack_timeout. If the client receives a PUBACK/PUBREC/PUBCOMP for a message after its completion has expired, the handler registered using #publish_completion_unknown_packet_id_handler will be invoked.

Note that this behavior is outside the scope of the MQTT 3.1.1 specification. The client's default behavior is therefore to wait forever for the server's corresponding acknowledgement.

Yields:

  • the handler to call with the ID of the expired packet

Returns:

  • (self)

Raises:

  • (ArgumentError)


126
127
128
129
130
131
132
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 126

def publish_completion_expiration_handler
  if block_given?
    @j_del.java_method(:publishCompletionExpirationHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling publish_completion_expiration_handler()"
end

- (self) publish_completion_handler { ... }

Sets a handler which will be called each time the publishing of a message has been completed.

For a message that has been published using

  • QoS 0 this means that the client has successfully sent the corresponding PUBLISH packet,
  • QoS 1 this means that a corresponding PUBACK has been received from the server,
  • QoS 2 this means that a corresponding PUBCOMP has been received from the server.

Yields:

  • handler called with the packetId

Returns:

  • (self)

Raises:

  • (ArgumentError)


106
107
108
109
110
111
112
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 106

def publish_completion_handler
  if block_given?
    @j_del.java_method(:publishCompletionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling publish_completion_handler()"
end

- (self) publish_completion_unknown_packet_id_handler { ... }

Sets a handler which will be called when the client receives a PUBACK/PUBREC/PUBCOMP with an unknown packet ID.

Yields:

  • the handler to call with the unknown packet ID

Returns:

  • (self)

Raises:

  • (ArgumentError)


137
138
139
140
141
142
143
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 137

def publish_completion_unknown_packet_id_handler
  if block_given?
    @j_del.java_method(:publishCompletionUnknownPacketIdHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling publish_completion_unknown_packet_id_handler()"
end

- (self) publish_handler { ... }

Sets handler which will be called each time server publish something to client

Yields:

  • handler to call

Returns:

  • (self)

Raises:

  • (ArgumentError)


147
148
149
150
151
152
153
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 147

def publish_handler
  if block_given?
    @j_del.java_method(:publishHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxMqtt::MqttPublishMessage)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling publish_handler()"
end

- (self) subscribe(topics) - (self) subscribe(topic, qos) - (self) subscribe(topics, subscribeSentHandler) { ... } - (self) subscribe(topic, qos, subscribeSentHandler) { ... }

Subscribes to the topic with a specified QoS level

Overloads:

  • - (self) subscribe(topics)

    Parameters:

    • topics (Hash{String => Fixnum})
      topics and related QoS levels to subscribe to
  • - (self) subscribe(topic, qos)

    Parameters:

    • topic (String)
      topic you subscribe on
    • qos (Fixnum)
      QoS level
  • - (self) subscribe(topics, subscribeSentHandler) { ... }

    Parameters:

    • topics (Hash{String => Fixnum})
      topics you subscribe on

    Yields:

    • handler called after SUBSCRIBE packet sent with packetid
  • - (self) subscribe(topic, qos, subscribeSentHandler) { ... }

    Parameters:

    • topic (String)
      topic you subscribe on
    • qos (Fixnum)
      QoS level

    Yields:

    • handler called after SUBSCRIBE packet sent with packetid

Returns:

  • (self)

Raises:

  • (ArgumentError)


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 178

def subscribe(param_1=nil,param_2=nil)
  if param_1.class == Hash && !block_given? && param_2 == nil
    @j_del.java_method(:subscribe, [Java::JavaUtil::Map.java_class]).call(Hash[param_1.map { |k,v| [k,::Vertx::Util::Utils.to_integer(v)] }])
    return self
  elsif param_1.class == String && param_2.class == Fixnum && !block_given?
    @j_del.java_method(:subscribe, [Java::java.lang.String.java_class,Java::int.java_class]).call(param_1,param_2)
    return self
  elsif param_1.class == Hash && block_given? && param_2 == nil
    @j_del.java_method(:subscribe, [Java::JavaUtil::Map.java_class,Java::IoVertxCore::Handler.java_class]).call(Hash[param_1.map { |k,v| [k,::Vertx::Util::Utils.to_integer(v)] }],(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
    return self
  elsif param_1.class == String && param_2.class == Fixnum && block_given?
    @j_del.java_method(:subscribe, [Java::java.lang.String.java_class,Java::int.java_class,Java::IoVertxCore::Handler.java_class]).call(param_1,param_2,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling subscribe(#{param_1},#{param_2})"
end

- (self) subscribe_completion_handler { ... }

Sets handler which will be called after SUBACK packet receiving

Yields:

  • handler to call. List inside is a granted QoS array

Returns:

  • (self)

Raises:

  • (ArgumentError)


157
158
159
160
161
162
163
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 157

def subscribe_completion_handler
  if block_given?
    @j_del.java_method(:subscribeCompletionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(::Vertx::Util::Utils.safe_create(event,::VertxMqtt::MqttSubAckMessage)) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling subscribe_completion_handler()"
end

- (self) unsubscribe(topic = nil) { ... }

Unsubscribe from receiving messages on given topic

Parameters:

  • topic (String) (defaults to: nil)
    Topic you want to unsubscribe from

Yields:

  • handler called after UNSUBSCRIBE packet sent

Returns:

  • (self)

Raises:

  • (ArgumentError)


208
209
210
211
212
213
214
215
216
217
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 208

def unsubscribe(topic=nil)
  if topic.class == String && !block_given?
    @j_del.java_method(:unsubscribe, [Java::java.lang.String.java_class]).call(topic)
    return self
  elsif topic.class == String && block_given?
    @j_del.java_method(:unsubscribe, [Java::java.lang.String.java_class,Java::IoVertxCore::Handler.java_class]).call(topic,(Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? ar.result : nil) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling unsubscribe(#{topic})"
end

- (self) unsubscribe_completion_handler { ... }

Sets handler which will be called after UNSUBACK packet receiving

Yields:

  • handler to call with the packetid

Returns:

  • (self)

Raises:

  • (ArgumentError)


197
198
199
200
201
202
203
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-mqtt/mqtt_client.rb', line 197

def unsubscribe_completion_handler
  if block_given?
    @j_del.java_method(:unsubscribeCompletionHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(event) }))
    return self
  end
  raise ArgumentError, "Invalid arguments when calling unsubscribe_completion_handler()"
end