0

i am using eclipse.paho.client.mqttv3-1.0.2.jar to subscribe and publish data i need to subscribe to multiple level of topics, according to http://mosquitto.org/man/mqtt-7.html we can use some wildcard option to subscribe all remaining levels of hierarchy. but when i try with mqttv3-1.0.2.jar i got an exception the topic name must not contain any wildcard characters # + with the following code:

String myTopicACK = "DATA/#";
int subQoS = 2;
myClient.subscribe(myTopicACK, subQoS);

i also tried with topic "DATA/*" somewhere i read that * is used for one level hierarchy. but no success.

Exception is

java.lang.IllegalArgumentException: The topic name MUST NOT contain any wildcard characters (#+)
    at org.eclipse.paho.client.mqttv3.MqttTopic.validate(MqttTopic.java:202)
    at org.eclipse.paho.client.mqttv3.MqttAsyncClient.getTopic(MqttAsyncClient.java:637)
    at org.eclipse.paho.client.mqttv3.MqttClient.getTopic(MqttClient.java:429)
    at PublishMe.runClient(PublishMe.java:154)
    at PublishMe.main(PublishMe.java:100)
Rawat
  • 461
  • 3
  • 6
  • 23
  • The single level wildcard is '+'. Please update the question with the actual exception message so we can see all the details – hardillb May 20 '16 at 10:35
  • Are you sure you're not trying to publish? Should be the correct syntax for subscriptions: `topicFilter` details in [`IMqttClient#subscribe(String[], int[])`](http://www.eclipse.org/paho/files/javadoc/org/eclipse/paho/client/mqttv3/IMqttClient.html#subscribe%28java.lang.String[],%20int[]%29) – zapl May 20 '16 at 10:40
  • no i am trying to subscribe not publish – Rawat May 20 '16 at 11:29
  • Line 154 from PublishMe is `myClient.subscribe(myTopicACK, subQoS);` ? – hardillb May 20 '16 at 11:39
  • @hardillb no no it was not line 154, sorry its my fault thanks i just copy/paste the code and didn't read the exception carefully, thanks for pointing out the mistake, thanks a lot. – Rawat May 20 '16 at 11:57
  • @hardillb one more thing i need to know that if client subscribed a topic with Qos 2 and client received the message than automatic acknowledge will be made by client to broker or client need to acknowledge separately the broker, if yes then how should client can acknowledge the broker – Rawat May 20 '16 at 12:22
  • Don't use comments to ask new questions – hardillb May 20 '16 at 12:25
  • ok sir i will ask in new question – Rawat May 20 '16 at 12:32

0 Answers0