Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The acknowledged messages extension provides reliable ordered messaging to the Bayeux protocol in cometd-jetty server and for the cometd-dojox and cometd-jquery clients.

Messages sent to each client are kept in an unacknowleged queue and only deleted when an acknowledgement is received. Unacknowledged messages are resent.

Client-server Negotiation

In order to enable message acknowledgement, both client and server must indicate that they support message acknowledgement. This is negotiated during handshake. On handshake, the client sends {"ext":{"ack": "true"}} to indicate that it supports message acknowledgement. If the server also supports message acknowledgment, it likewise replies with {"ext":{"ack": "true"}}.

Enabling server-side for cometd-jetty

...

Code Block
bayeux.addExtension(new AcknowledgedMessagesExtension());

AcknowledgedMessagesExtension

The AcknowledgedMessageExtension is a per server extension that monitors handshakes from new client, looking for clients that also support the acknowledged message extension and then adds the AcknowledgedMessagesClientExtension to each client on handshake.

AcknowledgedMessagesClientExtension

Once added to a client, the AcknowledgedMessagesClientExtension prevents messages being delivered on any request other than a /meta/connect so to prevent the possibility of out of order delivery. The extension also maintains a list of unacked messages and intercepts the /meta/connect traffic to insert and check ack IDs.

...

Code Block
    <script type="text/javascript" src="../../jquery/jquery.cometd.js"></script>

Details

In order to enable message acknowledgement, both client and server must indicate that they support message acknowledgement. This is negotiated during handshake. On handshake, the client sends {"ext":{"ack": "true"}} to indicate that it supports message acknowledgement. If the server also supports message acknowledgment, it likewise replies with {"ext":{"ack": "true"}}.

The extension does not insert ack IDs to every message, as this would impose a significant burden on the server for messages sent to multiple clients (which would need to be reserialized to json for each client). Instead the ack id is inserted in the ext field of the /meta/connect messages that are associated with message delivery. Each /meta/connect request contains the ack ID of the last received ack response: "ext":{"ack": 42}. Similarly, each ack response contains an ext ack ID that uniquely identifies the batch of responses sent.

If a /meta/connect message is received with an ackId lower that any unacknowledged messages held by the extension, then these messages are requeued prior to any more recently queued messages and the /meta/connect response sent with a new ack ID.

Demo

There is an example of acknowledged messages in the dojox chat demo that comes bundled with cometd.

...

Point your browser to http://localhost:8080/examples/chat/ and make sure to check "Enable reliable messaging?".

This will give you one extra option, "Acknowledge incoming messages", after you have joined. If checked, it will automatically acknowledge all incoming messages. If unchecked, it will not acknowledge incoming messages, which will make the server re-send these messages on next /meta/connectUse two different browsers instances to initial a chat session, then briefly disconnect one browser from the network (work offline option will do this). While one browser is disconnected, type some chat in the other browser and this will be received when the disconnected browser is reconnected to the network.

Note that if the disconnected browser is disconnected for in excess of maxInterval (default 10s), then the client will be timed out and the unacknowledged queue discarded.

Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery