Tag: rpc

  • CometD RemoteCall APIs

    CometD is a library collection that allows developers to write web messaging applications: you can send messages from servers to client, from clients to servers, from clients to other clients (via servers), and from server to server (using its clustering solution).
    I wrote about these styles of communications in a previous blog post.
    CometD 3.0.3 has been released, and it ships a new feature: a simpler API for remote calls.
    Most web messaging applications typically just need the concept of message exchanges: they don’t need a request/response paradigm (although they may require some form of acknowledgment that the message has been received by the server).
    However, for certain use cases, the application may need a way to send a message that requires a response, effectively using messages to implement remote procedure calls.
    CometD has always supported this use case through the use of service channels.
    However, applications had to write some code to correlate the request with the response and to handle timeouts and errors. Not much code, but still.
    CometD 3.0.3 introduces a new, simpler API to perform remote calls, that takes care under the hood to perform the request/response correlation and to handle timeouts and errors.
    From a JavaScript client you can now do (full docs):

    cometd.remoteCall("findContacts", { status: "online" }, 5000, function(response)
    {
        if (response.successful)
            displayContacts(response.data);
    });
    

    You specify a target for the remote call ("findContacts"), the argument object ({status:"online"}), the timeout in milliseconds for the call to complete (5000), and a function that handles the response.
    On the server side, you define a method target of the remote call using the annotation @RemoteCall (full docs):

    @Service
    public class RoomService
    {
        @RemoteCall("findContacts")
        public void findContacts(RemoteCall.Caller caller, Object data)
        {
            Map filter = (Map)data;
            ServerSession client = caller.getServerSession();
            try
            {
                List contacts = findContacts(client, filter);
                // Respond to the client with a success.
                caller.result(contacts);
            }
            catch (Exception x)
            {
                // Respond to the client with a failure.
                caller.failure(x.getMessage());
            }
        }
    }
    

    The target method may implement its logic in a different thread (this is recommended if the computation takes a long time), or even forward the request to another node via an OortService.
    The target method must respond to the caller, but it may also broadcast other messages or send to the caller additional messages along with the response.
    The possibilities are limitless.
    Contacts us if you have any question or if you want commercial support for your CometD application development and support.

  • CometD 3: RPC, PubSub, Peer-to-Peer Web Messaging

    A couple of months ago the CometD Project released its third major version, CometD 3.0.0 (announcement).
    Since then I wanted to write a blog about this major release, but work on HTTP 2 kept me busy.
    Today CometD 3.0.1 was released, so it’s time for a new CometD blog entry.
    CometD is an open source (Apache 2 licensed) project that started in 2008 under the umbrella of the Dojo Foundation, and already at the time it designed a web application messaging protocol named Bayeux.
    Similar efforts have started more recently, see for example WAMP.
    The Bayeux protocol is transport independent (works with HTTP and WebSocket) which allows CometD to easily fallback to HTTP when WebSocket, for any reason, does not work. Of course it works also with SPDY and HTTP 2.
    The Bayeux protocol supports two types of message delivery: the pubsub (broadcast) message delivery, and the peer-to-peer message delivery.
    In the pubsub style, a publisher sends a message to the server, which broadcast it to all clients that subscribed.
    In the peer-to-peer style, a sender sends a message to the server, which then decide what to do: it may broadcast the message to certain clients only, or to only one, or back to the original sender. This latter case allows for an implementation to offer RPC (remote procedure call) message delivery.
    Bayeux is also an extensible protocol, that allows to implement extensions on top of the protocol itself, so that implementations can add additional features such as time synchronization between client and server, and various grades of reliable message delivery (also called “quality of service” by MQTT).
    The CometD Project is an implementation of the Bayeux protocol, and over the years implemented not only the major features that the Bayeux protocol enables (pubsub messaging, peer-to-peer messaging, RPC messaging, message acknowledgment, etc.), but also additional features that make CometD the right choice if you have a web messaging use case.
    One such features is a clustering system, called Oort, that enables even more features such as tracking which node a client is connected to (Seti) and distributed objects and services.
    CometD 3.x leverages the standards for its implementation.
    In particular, it ships a HTTP transport based on the Servlet 3.1 Async I/O API, which makes CometD very scalable (no threads will be blocked by I/O operations).
    Furthermore, it ships a WebSocket transport based on the standard Java WebSocket API, also using asynchronous features, that make CometD even more scalable.
    If you have a web messaging use case, being it RPC style, pubsub style or peer-to-peer style, CometD is the one stop shop for you.
    Webtide provides commercial support for CometD, so you are not alone when using CometD. You don’t have to spend countless hours googling around in search of solutions when you can have the CometD committers helping you to design, deploy and scale your project.
    Contact us.