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

topic reflection in aws bridge & docs update #1479

Merged
merged 4 commits into from
Oct 10, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/en_US/bridges/assets/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions docs/en_US/bridges/aws-iot-core-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ Here's how to configure it on the AWS IoT Core side. Note: The Configuration pre



2. Download your Certificates at **Security** -> **Certificates** page.
2. Download your Certificates at **Security** -> **Certificates** page. Attach Policy to Certificates and attach Certificates to Things.

![Certification](./assets/certs.png)



3. Create a corresponding MQTT client behavior authentication policy at **Security **-> **Policies** page. And defines the client identifier, publish/subscribe topics, these parameters will be used in NanoMQ Bridge.
3. Create a corresponding MQTT client behavior authentication policy at **Security**-> **Policies** page. And defines the client identifier, publish/subscribe topics, these parameters will be used in NanoMQ Bridge.

![Policy](./assets/policy.png)

Expand Down Expand Up @@ -126,12 +126,12 @@ bridges.aws.c1 {
subscription = [
{
remote_topic = "cmd/topic1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd/topic3

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a problem, remote_topic and local_topic are not strongly correlated.

local_topic = "topic1"
local_topic = "topic3"
qos = 0
},
{
remote_topic = "cmd/topic2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd/topic4

local_topic = "topic2"
local_topic = "topic4"
qos = 1
}
]
Expand Down Expand Up @@ -230,10 +230,10 @@ $ nanomq start --old_conf nanomq.conf

Now you can verify whether the bridging channel is working by publishing a message to NanoMQ. Then check on the MQTT test client tool in AWS IoT Core.

For example, publish a message `hello` locally to the bridge topic `topic_1` of NanoMQ,
For example, publish a message `hello` locally to the bridge topic `topic1` of NanoMQ,

```bash
$ ./nanomq_cli pub -h "local.broker.address" -t "topic_1" -m "hello" -q 1
$ ./nanomq_cli pub -h "local.broker.address" -t "topic1" -m "hello" -q 1
```

On AWS MQTT test client menu:
Expand Down
Binary file modified docs/zh_CN/bridges/assets/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions docs/zh_CN/bridges/aws-iot-core-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ sudo ninja install



2. 在 **安全性** -> **证书** 处下载相关的 CRT 证书。
2. 在 **安全性** -> **证书** 处下载相关的 CRT 证书,并将策略附加到证书上,证书附加到物品上

![Certification](./assets/certs.png)

Expand Down Expand Up @@ -123,12 +123,12 @@ bridges.aws.c1 {
subscription = [
{
remote_topic = "cmd/topic1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd/topic3

local_topic = "topic1"
local_topic = "topic3"
qos = 0
},
{
remote_topic = "cmd/topic2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd/topic4

local_topic = "topic2"
local_topic = "topic4"
qos = 1
}
]
Expand Down Expand Up @@ -222,10 +222,10 @@ $ nanomq start --old_conf nanomq.conf

用户可以在 AWS IoT Core 的 MQTT 测试客户端工具上验证桥接是否成功。

如在本地向 NanoMQ 的桥接主题 `topic_1`发布一条消息 `hello`:
如在本地向 NanoMQ 的桥接主题 `topic1`发布一条消息 `hello`:

```bash
$ ./nanomq_cli pub -h "local.broker.address" -t "topic_1" -m "hello" -q 1
$ ./nanomq_cli pub -h "local.broker.address" -t "topic1" -m "hello" -q 1
```

即可在AWS 界面看到:
Expand Down
15 changes: 12 additions & 3 deletions nanomq/aws_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,19 @@ handle_recv_publish(MQTTPublishInfo_t *pub_info, uint16_t packet_id,
nng_mqtt_msg_set_publish_payload(
pub_msg, (uint8_t *) pub_info->pPayload, pub_info->payloadLength);

nng_mqtt_msg_set_publish_qos(pub_msg, pub_info->qos);
nng_mqtt_msg_set_publish_retain(pub_msg, pub_info->retain);
nng_mqtt_msg_set_publish_topic(pub_msg, pub_info->pTopicName);
nng_mqtt_msg_set_publish_topic_len(pub_msg, pub_info->topicNameLength);
for (int i = 0; i < node->sub_count; i++) {
if (strncmp(pub_info->pTopicName,
node->sub_list[i]->remote_topic,
node->sub_list[i]->remote_topic_len) == 0) {
nng_mqtt_msg_set_publish_topic(
pub_msg, node->sub_list[i]->local_topic);
nng_mqtt_msg_set_publish_topic_len(
pub_msg, node->sub_list[i]->local_topic_len);
nng_mqtt_msg_set_publish_qos(
pub_msg, node->sub_list[i]->qos);
}
}

nng_msg *msg = NULL;
if ((rv = encode_common_mqtt_msg(
Expand Down
2 changes: 1 addition & 1 deletion nanomq/tests/bridge_aws_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
int
main()
{
char *cmd_sub[] = {"mosquitto_sub", "-h", "127.0.0.1", "-p", "1881", "-t", "nmqtest", "-V", "mqttv5", NULL};
char *cmd_sub[] = {"mosquitto_sub", "-h", "127.0.0.1", "-p", "1881", "-t", "nmqtest_sub", "-V", "mqttv5", NULL};

char *cmd_pub= "mosquitto_pub -h 127.0.0.1 -p 1881 -t nmqtest_lo -m message-to-aws -V mqttv5";

Expand Down
2 changes: 1 addition & 1 deletion nanomq/tests/nanomq_aws_test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bridges.aws.c1 {
},
{
remote_topic = "nmqtest"
local_topic = "nmqtest2"
local_topic = "nmqtest_sub"
qos = 0
}
]
Expand Down
Loading