Eclipse Paho MQTT Client utility

129 views
Skip to first unread message

Binil Pai

unread,
Jan 21, 2015, 6:44:51 AM1/21/15
to mq...@googlegroups.com
Hi ,

I am developing a subscriber code in eclipse and when I tested directly using mosquitto pub(mosquitto_pub -t routes/Example01 -m 32 -q 1) it was showing the results in the eclipse itself.

But when I tried to publish via the Eclipse Paho MQTT Client utility it is not showing the result in the eclipse. The subscription and publish result only showing in the Paho utility itself not in the program where I written the Subscriber code.

Attached the jpeg for the same and please help on this regard

Regards
Binil
1PahoUtilitySubscriberTesting.jpg
2PahoUtilityTesting.jpg
3PublishUsingMosquito.jpg
4SubscriberWorkingFineWithMosquitoPublisher.jpg

张斌

unread,
Jan 21, 2015, 10:50:27 AM1/21/15
to mq...@googlegroups.com
  
  Why not paste or attach your subscriber code?  The image is not clear enough.

Binil Pai

unread,
Jan 21, 2015, 11:06:46 AM1/21/15
to mq...@googlegroups.com
Hi ,

Please find the attached code...Issue is not with the code as it is working fine with the mosqitto publisher..Only I am not able to run via Paho Utility tool.

Regards
Binil
Subscribe.java
Example.java

张斌

unread,
Jan 22, 2015, 1:25:06 AM1/22/15
to mq...@googlegroups.com
 Not sure what's Callback in your code, but the following code is working fine.
 
 
 public static void main(String[] args) {

        try {

            /** a. Create an instance of MQTT client */

            MqttClient client = new MqttClient(Example.TCPAddress, Example.clientId);


            /** b. Prepare connection options */

            // Callback callback = new Callback(Example.clientId);

            client.setCallback(new MqttCallback() {

                @Override

                public void connectionLost(Throwable cause) {

                    cause.printStackTrace();

                }


                @Override

                public void messageArrived(String topic, MqttMessage message) throws Exception {

                    System.out.println("Topic=" + topic + ", msg=" + message);

                }


                @Override

                public void deliveryComplete(IMqttDeliveryToken token) {

                }


            });

            MqttConnectOptions conOptions = new MqttConnectOptions();

            conOptions.setCleanSession(Example.cleanSession);

            conOptions.setKeepAliveInterval(Example.keepAliveInterval);


            /** c. Connect to broker with the connection options */

            client.connect();

            System.out.println("Subscribing to topic \"" + Example.subTopicString + "\" for client instance \""

                    + client.getClientId() + "\" using QoS " + Example.QoS + ". Clean session is "

                    + Example.cleanSession);


            /** d. subscribe interested topics */

            client.subscribe(Example.subTopicString, Example.QoS);

            System.out.format("Subscribing to topic %s \n for client %s using QoS %d \n\n"

                    + "Press Q<Enter> to quit \n\n", Example.subTopicString, Example.clientId, Example.QoS);

            Scanner scanner = new Scanner(System.in);

            for (String input = ""; !input.equalsIgnoreCase("q"); input = scanner.nextLine())

                ;


            // e. Disconnect to broker

            client.disconnect();

            System.out.println("Finished");

        }

        catch (Exception e) {

            e.printStackTrace();

        }

    }


Binil Pai

unread,
Jan 22, 2015, 8:19:30 AM1/22/15
to mq...@googlegroups.com
Hi ,

The client id should be different for the publisher and subscriber for running the paho utility and now once I changed it is working fine for me.


Regards
Binil

On Wednesday, January 21, 2015 at 5:14:51 PM UTC+5:30, Binil Pai wrote:
Reply all
Reply to author
Forward
0 new messages