Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse SmartHome » o.e.s.i.t.m.MqttBrokerConnection.addconsumer() send a wrong wildcard format instead of '+' in Topic(MqttBrokerConnection.addconsumer() use wrong wildcard format to MQTT Broker)
o.e.s.i.t.m.MqttBrokerConnection.addconsumer() send a wrong wildcard format instead of '+' in Topic [message #1773283] Tue, 26 September 2017 04:46 Go to next message
Felix Lo is currently offline Felix LoFriend
Messages: 8
Registered: October 2015
Junior Member
Following is the implementation of addconsumer. Problem that i am facing is the line with <<<-----. I treplaces all '+' with regex format which i think MQTT broker like mosquitto do not understand. I have also attached an output from mosquitto when a topic has '+' character in it.
public boolean addConsumer(MqttMessageSubscriber subscriber) throws MqttException {
String topic = subscriber.getTopic();
// Prepare topic for regex pattern matching taking place in messageArrived.
topic = StringUtils.replace(StringUtils.replace(topic, "+", "[^/]"), "#", "."); <<<------
synchronized (consumers) {
List subscriberList = consumers.get(topic);
if (subscriberList == null) {
subscriberList = new ArrayList<>();
}
subscriberList.add(subscriber);
consumers.put(topic, subscriberList);
}
if (isConnected()) {
try {
client.subscribe(topic, qos);
} catch (org.eclipse.paho.client.mqttv3.MqttException e) {
throw new MqttException(e);
}
}
return true;
}



MOSQUITTO.log
1506352001: Received SUBSCRIBE from openhab
1506352001: cctvchannel/motion_alert/2/2/[^/]/reply (QoS 0)
1506352001: openhab 0 cctvchannel/motion_alert/2/2/[^/]/reply
1506352001: Sending SUBACK to openhab
1506352001: Received SUBSCRIBE from openhab
1506352001: cctvchannel/motion_alert/2/3/[^/]/reply (QoS 0)
1506352001: openhab 0 cctvchannel/motion_alert/2/3/[^/]/reply
1506352001: Sending SUBACK to openhab
1506352006: Received SUBSCRIBE from openhab
Re: o.e.s.i.t.m.MqttBrokerConnection.addconsumer() send a wrong wildcard format instead of '+' in To [message #1773333 is a reply to message #1773283] Tue, 26 September 2017 14:26 Go to previous message
Markus Rathgeb is currently offline Markus RathgebFriend
Messages: 100
Registered: August 2014
Senior Member

Interesting, I didn't realized that replace yet. Why do we replace a +? It is a valid wildcard.
Previous Topic:Compilation Error
Next Topic:Changing readonly at runtime
Goto Forum:
  


Current Time: Mon Jun 18 02:28:14 GMT 2018

Powered by FUDForum. Page generated in 0.01990 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top