Is there any notification mechanism to inform "Register RPC" or "Subscribe topic" completion

16 views
Skip to first unread message

jingya...@gmail.com

unread,
Oct 3, 2018, 11:38:54 AM10/3/18
to CppWAMP
Hi All,
I am trying to use CPPWAMP to complete some data backend. The efficiency of CPPWAMP is amazing :) I really like that. however recently I found a issue when I register a RPC in server part and subscribe a topic a topic in client part, My understanding is that the register RPC and subscribe topics calls are async fashion which means never blocked. how can I know these calls are completed? I found sometimes there is a timing issue that the client call the RPC before the server register it, Is there way to know the register RPC call(enroll()) and subscribe topic(subscribe()) is done? Thank you! 

Cheers,

Jean  

Emile Cormier

unread,
Oct 3, 2018, 12:12:43 PM10/3/18
to CppWAMP
When using CoroSession, the enroll and subscribe methods won't return until the router acknowledges these messages. When using Session, the enroll and subscribe methods both take an asynchronous handler that is invoked when the router acknowledges them.

If your client and server are running in separate programs, I'm afraid that the WAMP protocol doesn't provide a built-in mechanism for indicating that the server is "ready". What you can do in this case is implement an is_ready RPC that returns true when the server has completed enrolling all its RPCs. In addition, you could implement a started pub-sub event that the server published when is has completed enrolling all its RPCs. The client would then do:
  • Connect and join a WAMP session
  • Subscribe to the started event.
  • Call the is_ready RPC
  • If is_ready returns false or an error, wait until the started event is published.
Providing a means to indicate that a server has registered all its RPCs and is ready is an interesting use case. I'm not sure if the WAMP community has even considered it. You should file an issue here: https://github.com/wamp-proto/wamp-proto

Hope this helps,
Emile

jingya...@gmail.com

unread,
Oct 4, 2018, 10:07:30 PM10/4/18
to CppWAMP
Hi Emile,
Thank you so much for your reply. I am using Session. according to your reply the enroll and subscribe should have some asynchronous handler, but I don't find this information in CPPWAMP wiki page, could you kindly please put some code snippet here or show me the link in wiki? My understanding is that I can get some callback function (as you mentioned "handler") when the RPC registration is done, am I right? Thanks!

Cheers,
Jean

Emile Cormier

unread,
Oct 5, 2018, 12:08:57 AM10/5/18
to CppWAMP
There are no tutorials yet for the Session class using the async API, but there is Doxygen documentation here: http://ecorm.github.io/cppwamp/doc/classwamp_1_1_session.html

Without testing it, this is what it would look like to use the async API:

session->enroll(
    Procedure("square"),
    basicRpc<void, int>([](int arg){return arg*arg;}),
    [](AsyncResult<Registration> reg)
    {
        if (!reg)
            cout << reg.errorCode() << "\n";
        else
            // chain to the next asynchronous operation
    }
);

where the 3rd argument is the asynchronous handler function. AsyncResult<Registration> can hold either a valid Registration value upon success, or a std::error_code upon failure.

I don't know when I'll have time to write the tutorials for the asynchronous API, sorry.

jingya...@gmail.com

unread,
Oct 5, 2018, 10:05:48 PM10/5/18
to CppWAMP
Hi Emile,
Thank you so much, that's what I am looking for, I missed this important document . I will work on it. Thanks again and have a great weekend!

Jean
Reply all
Reply to author
Forward
0 new messages