简体   繁体   English

自桥接 Mosquitto MQTT 代理

[英]Self bridging Mosquitto MQTT broker

I am trying to self-bridge a mosquitto broker.我正在尝试自桥接蚊子经纪人。 Let me explain the scenario for which I am doing this.让我解释一下我这样做的场景。

We have 2 parts to our application.我们的应用程序有 2 个部分。 One which is concerned with processing data and other is a modbus service that reads data from PLC devices.一个与处理数据有关,另一个是从 PLC 设备读取数据的 modbus 服务。 The processing part of the application is capable of handling multiple clients.应用程序的处理部分能够处理多个客户端。 I want to setup a test and a production tenant for the same client.我想为同一个客户端设置测试和生产租户。 The reason behind this is that this would give our clients the liberty to play around with the test tenant where as the production won't be affected by this.这背后的原因是,这将使我们的客户可以自由地与测试租户一起玩,因为生产不会受到此影响。

The test client both sends as well as receives data from the broker.测试客户端从代理发送和接收数据。 It is important that we don't send the test tenant's data to our modbus service.重要的是我们不要将测试租户的数据发送到我们的 modbus 服务。 The topics follow the following format.主题遵循以下格式。

company/service/test/+ for the test client and company/service/prod/+ for the prod client. company/service/test/+用于测试客户端, company/service/prod/+用于 prod 客户端。

The modbus service send data to the same broker in the format company/service/prod/+ . modbus 服务以company/service/prod/+格式将数据发送到同一个代理。

Is there a way for me to remap this topic to company/service/test/+ so that both test and prod clients can receive data from the broker.有没有办法让我将此主题重新映射到company/service/test/+以便 test 和 prod 客户端都可以从代理接收数据。

address 127.0.0.1:41888
topic /company/values/prod/+ in 2   
topic /company/values/prod/+ out 2 "" /company/values/test/+
remote_clientid test
remote_username mqttuser
remote_password broker-123

Remember I have a single broker instance and I'm trying to self bridge on this.请记住,我有一个单一的代理实例,并且我正在尝试对此进行自我桥接。

In my above configuration, the remapping doesn't happen cause it's not a valid prefix.在我上面的配置中,重新映射不会发生,因为它不是一个有效的前缀。

Can someone please help me figure out how to approach this?有人可以帮我弄清楚如何解决这个问题吗?

The problem is the + on the end of the output topic mapping in问题是输出主题映射末尾的+

topic /company/values/prod/+ out 2 "" /company/values/test/+

You want你要

topic + out 2 /company/values/prod/ /company/values/test/

This will strip off /company/values/prod/ and replace it with /company/values/test/这将剥离/company/values/prod/并将其替换为/company/values/test/

You also want to remove the first topic line ( topic /company/values/prod/+ in 2 ) as this will lead to an infinity publish loop for any message published to /company/values/prod/+您还想删除第一个主题行( topic /company/values/prod/+ in 2 ),因为这将导致发布到/company/values/prod/+任何消息的无限发布循环

ps starting topics with a leading / while valid in the spec is a REALLY bad idea, as it breaks things when you get round to needing shared subscriptions and injects an unneeded null to the start of every topic. ps 使用前导/开始主题,而在规范中有效是一个非常糟糕的主意,因为当您开始需要共享订阅并在每个主题的开头注入一个不需要的空值时,它会破坏事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM