Merge pull request #921 from eeff/eeff/dev

fix(nano-mqtt): keep sending messages when caching enabled
This commit is contained in:
fengzeroz
2022-11-18 16:09:36 +08:00
committed by GitHub
3 changed files with 21 additions and 5 deletions
+12 -4
View File
@@ -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;
}
+3 -1
View File
@@ -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;
+6
View File
@@ -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: