Method: Mosquitto::Client#on_publish

Defined in:
ext/mosquitto/client.c

#on_publish {|mid| ... } ⇒ Boolean

Set the publish callback. This is called when a message initiated with Mosquitto::Client#publish has been sent to the broker successfully.

Examples:

client.on_publish{|mid| p :published }

Yields:

  • (mid)

Returns:

  • (Boolean)

Yields:

  • publish callback

Yield Parameters:

  • mid (Integer)

    the message id of the sent message

Returns:

  • (true)

    on success

Raises:

  • (TypeError, ArgumentError)

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



2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
# File 'ext/mosquitto/client.c', line 2034

static VALUE rb_mosquitto_client_on_publish(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->publish_cb)) rb_gc_unregister_address(&client->publish_cb);
    mosquitto_publish_callback_set(client->mosq, rb_mosquitto_client_on_publish_cb);
    client->publish_cb = cb;
    rb_gc_register_address(&client->publish_cb);
    return Qtrue;
}