Jetty has moved!
Jetty is a project at the Eclipse Foundation.
Homepage:http://www.eclipse.org/jetty
Downloads: http://download.eclipse.org/jetty/
Documentation:http://www.eclipse.org/jetty/documentation/current/
About:http://www.eclipse.org/jetty/about.php
Jetty Powered:http://www.eclipse.org/jetty/powered/
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
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Acknowledged Messages

The acknowledged messages feature provides some degree of reliable messaging to the Bayeux protocol in Jetty. When the client receives a message from the server, it sends back an acknowledgement of message receipt. If the server receives no acknowledgement, it assumes that the message did not reach the client, and will re-send all unacknowledged messages until these have been acked.

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"}}.

Acknowledged messages, server-side

Acknowledged messaging on the server is implemented as a pair of extensions.

Enabling

Add the AcknowledgedMessagesExtension to your list of Bayeux extensions.

AcknowledgedMessagesExtension

A Bayeux extension. It adds the AcknowledgedMessagesClientExtension to each client on handshake, if the client indicates that it supports message acks (has ext.ack in its handshake message)

AcknowledgedMessagesClientExtension

A Client extension, added to the client by the Bayeux AcknowledgedMessagesExtension. This extension keeps track of the unacked queue, a list of messages which have been sent but have not yet been acknowledged by the client.

All outgoing messages are added to the unacked queue just before they are sent out. If there are outgoing messages, the outgoing poll reply is given a batch id to identify the current batch of outgoing messages.

Every incoming /meta/connect is checked for an ack, and any batches that have been acknowledged are discarded. All remaining messages are then moved from the unacked queue to the outgoing message queue to be sent again. As they are sent out, they are moved back to the unacked queue, completing the cycle.

The messages are processed in the following methods:

  • rcvMeta - check for a batch id and resend unacked messages
  • sendMeta - add and increment the batch id
  • send - copy message to the unacked queue

Acknowledged messages, client-side

An example implementation of acknowledged messaging is this sample extension for the dojox cometd library, which is used by the ackHandler in the dojo chat demo.

If message acknowledgement is enabled, the client should note the batch id while processing incoming messages, and then send back an acknowledgement to the server acknowledging message receipt. Responsibility for handling duplicate messages is on the client (in case the client received, but did not ack; or the client acked, but the ack did not reach the server).

Enabling

On the client side, the client must include an "ack" field in the extension space of its handshake message, to indicate that it supports message acknowledgement.

Demo

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

To run the demo, download the Jetty implementation of cometd, then:

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/connect.

  • No labels
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