Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions doc/developer-guide/jsonrpc/jsonrpc-api.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,7 @@ Description
Interact with plugins. Send a message to plugins. All plugins that have hooked the ``TSLifecycleHookID::TS_LIFECYCLE_MSG_HOOK`` will receive a callback for that hook.
The :arg:`tag` and :arg:`data` will be available to the plugin hook processing. It is expected that plugins will use :arg:`tag` to select relevant messages and determine the format of the :arg:`data`.


Parameters
~~~~~~~~~~

Expand All @@ -1382,6 +1383,24 @@ Result

The response will contain the default `success_response` or an error. :ref:`jsonrpc-node-errors`.

If plugins are not yet ready to handle any messages, then the following error will be set:

.. code-block:: json

{
"error": {
"code": 9,
"message": "Error during execution",
"data": [
{
"code": 5000,
"message": "Plugin is not yet ready to handle any messages."
}
]
}
}


Examples
~~~~~~~~

Expand Down
7 changes: 7 additions & 0 deletions mgmt/rpc/handlers/plugins/Plugins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct PluginMsgInfo {
std::string data;
std::string tag;
};

} // namespace
namespace YAML
{
Expand All @@ -58,6 +59,12 @@ namespace err = rpc::handlers::errors;
ts::Rv<YAML::Node>
plugin_send_basic_msg(std::string_view const &id, YAML::Node const &params)
{
// The rpc could be ready before plugins are initialized.
// We make sure it is ready.
if (!lifecycle_hooks) {
return err::make_errata(err::Codes::PLUGIN, "Plugin is not yet ready to handle any messages.");
}

ts::Rv<YAML::Node> resp;
try {
// keep the data.
Expand Down