Method: Mosquitto::Client#on_message

Defined in:
ext/mosquitto/client.c

#on_message {|msg| ... } ⇒ Boolean

Set the message callback. This is called when a message is received from the broker.

Examples:

client.on_message{|msg| p msg }

Yields:

  • (msg)

Returns:

  • (Boolean)

Yields:

  • message callback

Yield Parameters:

Returns:

  • (true)

    on success

Raises:

  • (TypeError, ArgumentError)

    if callback is not a Proc or if the method arity is wrong



2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
# File 'ext/mosquitto/client.c', line 2062

static VALUE rb_mosquitto_client_on_message(int argc, VALUE *argv, VALUE obj)
{
    VALUE proc, cb;
    MosquittoGetClient(obj);
    rb_scan_args(argc, argv, "01&", &proc, &cb);
    MosquittoAssertCallback(cb, 1);
    if (!NIL_P(client->message_cb)) rb_gc_unregister_address(&client->message_cb);
    mosquitto_message_callback_set(client->mosq, rb_mosquitto_client_on_message_cb);
    client->message_cb = cb;
    rb_gc_register_address(&client->message_cb);
    return Qtrue;
}