Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rest APIs for subscription & unsubscription of bridge #1222

Merged
merged 5 commits into from
May 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions nanomq/aws_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ subscribe_to_topic(MQTTContext_t *mqtt_ctx, conf_bridge_node *node)

/* This example subscribes to only one topic and uses QOS1. */
for (size_t i = 0; i < node->sub_count; i++) {
sub_list[i].qos = node->sub_list[i].qos;
sub_list[i].pTopicFilter = node->sub_list[i].topic;
sub_list[i].topicFilterLength = node->sub_list[i].topic_len;
sub_list[i].qos = node->sub_list[i]->qos;
sub_list[i].pTopicFilter = node->sub_list[i]->topic;
sub_list[i].topicFilterLength = node->sub_list[i]->topic_len;
}

/* Generate packet identifier for the SUBSCRIBE packet. */
Expand Down
24 changes: 12 additions & 12 deletions nanomq/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ bridge_connect_cb(nng_pipe p, nng_pipe_ev ev, void *arg)
nng_mqtt_topic_qos_array_create(param->config->sub_count);
for (size_t i = 0; i < param->config->sub_count; i++) {
nng_mqtt_topic_qos_array_set(topic_qos, i,
param->config->sub_list[i].topic,
param->config->sub_list[i].qos, 1, 0, 0);
param->config->sub_list[i]->topic,
param->config->sub_list[i]->qos, 1, 0, 0);
log_info("Bridge client subscribed topic %s (qos %d).",
param->config->sub_list[i].topic,
param->config->sub_list[i].qos);
param->config->sub_list[i]->topic,
param->config->sub_list[i]->qos);
}
nng_mqtt_client *client = param->client;

Expand Down Expand Up @@ -593,13 +593,13 @@ quic_ack_cb(void *arg)
nng_mqtt_topic_qos *topic_qos =
nng_mqtt_topic_qos_array_create(1);
nng_mqtt_topic_qos_array_set(topic_qos, 0,
param->config->sub_list[i].topic,
param->config->sub_list[i].qos, 1, 0, 0);
param->config->sub_list[i]->topic,
param->config->sub_list[i]->qos, 1, 0, 0);
log_info("Quic bridge client subscribe to "
"topic (QoS "
"%d)%s.",
param->config->sub_list[i].qos,
param->config->sub_list[i].topic);
param->config->sub_list[i]->qos,
param->config->sub_list[i]->topic);
nng_mqtt_subscribe_async(
client, topic_qos, 1, NULL);
nng_mqtt_topic_qos_array_free(topic_qos, 1);
Expand All @@ -610,12 +610,12 @@ quic_ack_cb(void *arg)
param->config->sub_count);
for (size_t i = 0; i < param->config->sub_count; i++) {
nng_mqtt_topic_qos_array_set(topic_qos, i,
param->config->sub_list[i].topic,
param->config->sub_list[i].qos, 1, 0, 0);
param->config->sub_list[i]->topic,
param->config->sub_list[i]->qos, 1, 0, 0);
log_info("Quic bridge client subscribed topic "
"(q%d)%s.",
param->config->sub_list[i].qos,
param->config->sub_list[i].topic);
param->config->sub_list[i]->qos,
param->config->sub_list[i]->topic);
}
// TODO support MQTT V5
nng_mqtt_subscribe_async(
Expand Down
8 changes: 4 additions & 4 deletions nanomq/conf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ get_bridge_config(conf_bridge *bridge, const char *node_name)

cJSON *sub_infos = cJSON_CreateArray();
for (size_t j = 0; j < node->sub_count; j++) {
cJSON *sub_obj = cJSON_CreateObject();
topics sub = node->sub_list[j];
cJSON * sub_obj = cJSON_CreateObject();
topics *sub = node->sub_list[j];
cJSON_AddStringOrNullToObject(
sub_obj, "topic", sub.topic);
cJSON_AddNumberToObject(sub_obj, "qos", sub.qos);
sub_obj, "topic", sub->topic);
cJSON_AddNumberToObject(sub_obj, "qos", sub->qos);
cJSON_AddItemToArray(sub_infos, sub_obj);
}

Expand Down