Method: Mosquitto::Client#on_subscribe

Defined in:
ext/mosquitto/client.c

#on_subscribe {|mid, granted_qos| ... } ⇒ Boolean

Set the subscribe callback. This is called when the broker responds to a subscription request.

Examples:

client.on_subscribe{|mid, granted_qos| p :subscribed }

Yields:

  • (mid, granted_qos)

Returns:

  • (Boolean)

Yields:

  • subscription callback

Yield Parameters:

  • mid (Integer)

    the message id of the subscribe message.

  • granted_qos (Array)

    an array of integers indicating the granted QoS for each of the subscriptions.

Returns:

  • (true)

    on success

Raises:

  • (TypeError, ArgumentError)

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



2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
# File 'ext/mosquitto/client.c', line 2092

static VALUE rb_mosquitto_client_on_subscribe(int argc, VALUE *argv, VALUE obj)
{
    VALUE proc, cb;
    MosquittoGetClient(obj);
    rb_scan_args(argc, argv, "01&", &proc, &cb);
    MosquittoAssertCallback(cb, 2);
    if (!NIL_P(client->subscribe_cb)) rb_gc_unregister_address(&client->subscribe_cb);
    mosquitto_subscribe_callback_set(client->mosq, rb_mosquitto_client_on_subscribe_cb);
    client->subscribe_cb = cb;
    rb_gc_register_address(&client->subscribe_cb);
    return Qtrue;
}