From 2706f2b4d7fd72f368ce31dda9580baab5fef378 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Fri, 18 Nov 2022 15:16:16 +0800 Subject: [PATCH 1/2] fix(nano-mqtt): keep sending messages when caching enabled --- plugins/nano-mqtt/mqtt_handle.c | 16 ++++++++++++---- plugins/nano-mqtt/mqtt_plugin.c | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/plugins/nano-mqtt/mqtt_handle.c b/plugins/nano-mqtt/mqtt_handle.c index 1b42d387..430dc1d1 100644 --- a/plugins/nano-mqtt/mqtt_handle.c +++ b/plugins/nano-mqtt/mqtt_handle.c @@ -333,7 +333,9 @@ int handle_write_response(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt_json, goto end; } - if (!neu_mqtt_client_is_connected(plugin->client)) { + if (0 == plugin->config.cache && + !neu_mqtt_client_is_connected(plugin->client)) { + // cache disable and we are disconnected rv = NEU_ERR_MQTT_FAILURE; goto end; } @@ -411,7 +413,9 @@ int handle_read_response(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt_json, goto end; } - if (!neu_mqtt_client_is_connected(plugin->client)) { + if (0 == plugin->config.cache && + !neu_mqtt_client_is_connected(plugin->client)) { + // cache disable and we are disconnected rv = NEU_ERR_MQTT_FAILURE; goto end; } @@ -449,7 +453,9 @@ int handle_trans_data(neu_plugin_t * plugin, return NEU_ERR_MQTT_IS_NULL; } - if (!neu_mqtt_client_is_connected(plugin->client)) { + if (0 == plugin->config.cache && + !neu_mqtt_client_is_connected(plugin->client)) { + // cache disable and we are disconnected return NEU_ERR_MQTT_FAILURE; } @@ -484,7 +490,9 @@ int handle_nodes_state(neu_plugin_t *plugin, neu_reqresp_nodes_state_t *states) goto end; } - if (!neu_mqtt_client_is_connected(plugin->client)) { + if (0 == plugin->config.cache && + !neu_mqtt_client_is_connected(plugin->client)) { + // cache disable and we are disconnected rv = NEU_ERR_MQTT_FAILURE; goto end; } diff --git a/plugins/nano-mqtt/mqtt_plugin.c b/plugins/nano-mqtt/mqtt_plugin.c index bb610d30..1f04d65c 100644 --- a/plugins/nano-mqtt/mqtt_plugin.c +++ b/plugins/nano-mqtt/mqtt_plugin.c @@ -95,6 +95,7 @@ static int config_mqtt_client(neu_plugin_t *plugin, neu_mqtt_client_t *client, return 0; } + // set log category as soon as possible to ease debugging rv = neu_mqtt_client_set_zlog_category(client, plugin->common.log); if (0 != rv) { plog_error(plugin, "neu_mqtt_client_set_zlog_category fail"); @@ -286,7 +287,8 @@ end: if (0 == rv) { plog_info(plugin, "start plugin `%s` success", plugin_name); } else { - plog_error(plugin, "start plugin `%s` failed", plugin_name); + plog_error(plugin, "start plugin `%s` failed, error %d", plugin_name, + rv); neu_mqtt_client_close(plugin->client); } return rv; From c76feca0e678c2b59cf651b068dd0b96846328c6 Mon Sep 17 00:00:00 2001 From: eeff <33566201+eeff@users.noreply.github.com> Date: Fri, 18 Nov 2022 15:21:09 +0800 Subject: [PATCH 2/2] fix(restful): handle mqtt error codes --- plugins/restful/http.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/restful/http.c b/plugins/restful/http.c index ff193b5a..37b9deef 100644 --- a/plugins/restful/http.c +++ b/plugins/restful/http.c @@ -289,6 +289,12 @@ int http_response(nng_aio *aio, neu_err_code_e code, char *content) case NEU_ERR_PLUGIN_NOT_RUNNING: case NEU_ERR_PLUGIN_TAG_NOT_READY: case NEU_ERR_PLUGIN_PACKET_OUT_OF_ORDER: + case NEU_ERR_MQTT_FAILURE: + case NEU_ERR_MQTT_IS_NULL: + case NEU_ERR_MQTT_INIT_FAILURE: + case NEU_ERR_MQTT_CONNECT_FAILURE: + case NEU_ERR_MQTT_SUBSCRIBE_FAILURE: + case NEU_ERR_MQTT_PUBLISH_FAILURE: status = NNG_HTTP_STATUS_OK; break; case NEU_ERR_EINTERNAL: