Class: VertxMqtt::MqttClient
- Inherits:
-
Object
- Object
- VertxMqtt::MqttClient
- 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)
- + (Boolean) accept?(obj)
-
+ (::VertxMqtt::MqttClient) create(vertx = nil, options = nil)
Return an MQTT client instance.
- + (Object) j_api_type
- + (Object) j_class
- + (Object) unwrap(obj)
- + (Object) wrap(obj)
Instance Method Summary (collapse)
-
- (String) client_id
The client identifier.
-
- (self) close_handler { ... }
Set a handler that will be called when the connection with server is closed.
-
- (self) connect(port = nil, host = nil, serverName = nil) { ... }
Connects to an MQTT server calling connectHandler after connection.
-
- (true, false) connected?
If the connection between client and remote server is established/open.
-
- (self) disconnect { ... }
Disconnects from the MQTT server calling disconnectHandler after disconnection.
-
- (self) exception_handler { ... }
Set an exception handler for the client, that will be called when an error happens in internal netty structures.
-
- (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.
-
- (self) ping_response_handler { ... }
Sets handler which will be called after PINGRESP packet receiving.
-
- (self) publish(topic = nil, payload = nil, qosLevel = nil, isDup = nil, isRetain = nil) { ... }
Sends the PUBLISH message to the remote MQTT server.
-
- (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.
-
- (self) publish_completion_handler { ... }
Sets a handler which will be called each time the publishing of a message has been completed.
-
- (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.
-
- (self) publish_handler { ... }
Sets handler which will be called each time server publish something to client.
-
- (self) subscribe(param_1 = nil, param_2 = nil)
Subscribes to the topic with a specified QoS level.
-
- (self) subscribe_completion_handler { ... }
Sets handler which will be called after SUBACK packet receiving.
-
- (self) unsubscribe(topic = nil) { ... }
Unsubscribe from receiving messages on given topic.
-
- (self) unsubscribe_completion_handler { ... }
Sets handler which will be called after UNSUBACK packet receiving.
Class Method Details
+ (Boolean) accept?(obj)
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
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,=nil) if vertx.class.method_defined?(:j_del) && !block_given? && == 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) && .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())),::VertxMqtt::MqttClient) end raise ArgumentError, "Invalid arguments when calling create(#{vertx},#{})" 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
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
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
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
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
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
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
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
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
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.
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.
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.
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
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
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
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
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
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 |