Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Post message automatically after connecting(Post automatically post messages to connect to the broker.)
Post message automatically after connecting [message #1709886] Thu, 01 October 2015 17:42 Go to next message
Jeff August is currently offline Jeff AugustFriend
Messages: 10
Registered: September 2015
Junior Member
Hello everyone!

I wonder if there is any way to do the publication on a topic previously established soon after I connect to the broker ?

The topic and the message will already be internally defined. I want to send after the connection is made ​​to obtain the return status of my topic.

Any suggestions will help a lot .

Cheers
Re: Post message automatically after connecting [message #1709919 is a reply to message #1709886] Thu, 01 October 2015 22:09 Go to previous messageGo to next message
Edward Woodhouse is currently offline Edward WoodhouseFriend
Messages: 12
Registered: September 2015
Junior Member
If you are using the Android Service you could add the message you want to pulish to the subscribe() method of the ActionListener class.
Re: Post message automatically after connecting [message #1710003 is a reply to message #1709919] Fri, 02 October 2015 14:44 Go to previous messageGo to next message
Jeff August is currently offline Jeff AugustFriend
Messages: 10
Registered: September 2015
Junior Member
Hi Edward , thank you for answering my question .

I've been looking ActionListener class in Subscribe method, but in this class seem to me that it just notifies you that there was an act of subscribing .

It seems to me that the connection is asynchronous, so I can not directly call publish () after connecting me . It seems so simple connect me and publish automatically. But in practice it is not.

If you have other suggestions , I am grateful.

Jeff
Re: Post message automatically after connecting [message #1710009 is a reply to message #1710003] Fri, 02 October 2015 15:30 Go to previous messageGo to next message
Edward Woodhouse is currently offline Edward WoodhouseFriend
Messages: 12
Registered: September 2015
Junior Member
You can publish to a channel you are not subscribed to but that client won't receive the message. You could try doing it in the connect() method of ActionListener. If you want to be receive the messages on that client you will need to subscribe first.
Re: Post message automatically after connecting [message #1710062 is a reply to message #1710009] Sat, 03 October 2015 14:25 Go to previous messageGo to next message
Jeff August is currently offline Jeff AugustFriend
Messages: 10
Registered: September 2015
Junior Member
I tried your suggestion and it seemed it was going to be all right. But a mistake is pointed out whenever I call the publish(). The error is always pointed to the first online publish () " EditText EDITTEXT = (EditText) connectionDetails.findViewById (R.id.lastWillTopic);" I think it's because of "connectionDetails" .

Now do not know if it's my lack of experience in java. I think we have to pass this parameter in the constructor standing at Connect ( ) in ActionListener class.

Connect () in ActionListener used:

Var listener = new Listener ();
var.publish ();

Listener used in the empty constructor .

Listener {
}

Is this the cause of my frustration ?
Re: Post message automatically after connecting [message #1710194 is a reply to message #1710062] Mon, 05 October 2015 09:24 Go to previous messageGo to next message
James Sutton is currently offline James SuttonFriend
Messages: 71
Registered: July 2015
Member
You probably want to implement an IMqttActionListener and pass it into the connect

Pretty rough idea below:

public class ConnectionListener implements IMqttActionListener {

    private Connection connection;


    public ConnectionListener() {
        // Maybe pass the Listener the client in the constructor?
    }
    @Override
    public void onSuccess(IMqttToken iMqttToken) {

        // Do your publish here using the client

    }

    @Override
    public void onFailure(IMqttToken iMqttToken, Throwable throwable) {

    }
}


final ConnectionListener callback = new ConnectionListener();
client.connect(connectionOptions, userContext, callback);


For reference, take a look at what the current Android sample does here:

http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.java.git/tree/org.eclipse.paho.android.service/org.eclipse.paho.android.sample/src/main/java/org/eclipse/paho/android/sample/ActionListener.java?h=develop

And then where it's used, here: http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.java.git/tree/org.eclipse.paho.android.service/org.eclipse.paho.android.sample/src/main/java/org/eclipse/paho/android/sample/ClientConnections.java?h=develop#n313
Re: Post message automatically after connecting [message #1710461 is a reply to message #1710194] Tue, 06 October 2015 22:50 Go to previous message
Jeff August is currently offline Jeff AugustFriend
Messages: 10
Registered: September 2015
Junior Member
Hi James ,

Thank you for offering this suggestion. This week I will try to apply it in my need . I hope to succeed . I'll post the results or any doubts here.

Cheers.
Previous Topic:Synchronous receive of topics with wild card
Next Topic:Link DLL to C project for an embedded system
Goto Forum:
  


Current Time: Thu Apr 18 10:43:09 GMT 2024

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

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

Back to the top