com.smartgwt.client.docs

## Interface Messaging

-     public interface Messaging

  ### Real-Time Messaging

  The optional Real-Time Messaging (RTM) module for Smart GWT allows browser-based web applications to:
  - publish and subscribe to HTTP messaging channels
  - send and receive messages via server push, for "real-time" updates without polling
  For examples of publish and subscribe messaging, see: @see Portfolio Grid and @see Stock Chart

  This functionality is currently supported for deployment on Java server platforms only, and requires a Power license or better as well as purchase of the Real-Time Messaging module. See http://smartclient.com/product for details, and see `LoadingOptionalModules` for instructions on setting up the Messaging module.

  ### Usage Summary

  Messaging works in terms of channels. A channel is an abitrary identifier for a destination for a message. When messages are sent to a channel, anyone subscribed to that channel receives the message.

  The same concept appears in JMS (Java Message Service), where the equivalent term to channel is "topic".

  Messages can be sent to a channel from either the client-side ( Messaging.send()) or server-side (ISCMessageDispatcher.send(), or equivalent JMS APIs to send a message to a Topic).

  You can subscribe to a channel from either the client-side ( Messaging.subscribe()) or server-side (ISCMessageDispatcher.register(), or equivalent JMS APIs to subscribe to a Topic).

  Channels can be used in any way the application needs. For example, a chat application similar to IRC would typically create a new channel every time 2 or more people want to talk to one another.

  ### Server API summary

  Server-side RTM interfaces are provided by the following classes in com.isomorphic.messaging:

  ISCMessageDispatcher
  Abstract class; use to obtain a concrete message dispatcher class.
  instance() returns a concrete ISCMessageDispatcher class capable of delivering responses within the JVM
  instance(RequestContext context) returns a concrete ISCMessageDispatcher class capable of delivering responses to web browsers
  send(ISCMessage msg) send a message
  register(ISubscriber subscriber) register this subscriber
  unregister(ISubscriber subscriber) unregister this subscriber
  subscribe(ISubscriber subscriber, String channel) subscribe a given subscriber to a given channel
  unsubscribe(ISubscriber subscriber, String channel) unsubscribe a given subscriber from a given channel
  boolean isSubscribed(ISubscriber subscriber, String channel) check to see if a given subscriber is subscribed to a given channel
  ISCMessage
  Message object.
  ISCMessage(String channel, Object data)
  ISCMessage(List channels, Object data) create a message bound for the specified channel(s) with the specified data payload
  ISubscriber
  Simple interface for a message subscriber. Required methods are:
  public void send(ISCMessage msg) throws Exception;
  public ISCMessage nextMessage(long timeout) throws Exception;
  ISCSubscriber Simple concrete implementation of ISubscriber. send() adds message to a queue and nextMessage() retrieves them.

  ### Configuration

  The Smart GWT message dispatcher can operate in simple mode or enterprise mode:

  - Simple mode uses an in-memory messaging delivery system with no message persistence, and can operate only in the context of a single JVM.
  - Enterprise mode uses Java Message Service (JMS) as the messaging backend, and can operate in a clustered environment.
  You can set the following properties in WEB-INF/classes/server.properties to control this mode and other parameters:

        # how often do we send keepalives to the client (ms)
               messaging.keepaliveInterval: 3000

        # how long the client waits after the keepaliveInterval before re-establishing
        # the connection (ms)
               messaging.keepaliveReestablishDelay: 1000

        # how long the client waits for the connect handshake to complete before
        # retrying
               messaging.connectTimeout: 4000

        # connection time to live - the maximum amount of time a persistent connection
        # is allowed to stay open before being re-established (ms)
               messaging.connectionTTL: 120000

        # total response size to pad out to in order to defeat intervening
        # bufferring by proxies (bytes)
               messaging.flushBufferSize: 8096

        # dispatcher to use for user registration/message queueing
        # com.isomorphic.messaging.LocalMessageDispatcher for simple one-jvm messaging
        # com.isomorphic.messaging.JMSMessageDispatcher for JMS-backed messaging
               messaging.dispatcherImplementer: com.isomorphic.messaging.LocalMessageDispatcher

        # jms configuration - for JMSMessageDispatcher only
               messaging.jms.context: _container_
               messaging.jms.jndiPrefix: jms
               messaging.jms.topicConnectionFactory: TopicConnectionFactory

  Example configurations for various populate JMS engines (ActiveMQ, JBoss, etc) can be found on the Isomorphic Public Wiki. Try searching for "messaging" or "jms" or the name of the engine you are trying to configure.

  ### Tips

  - We recommend developing using a single container with the LocalMessageDispatcher and then switching to the JMSMessageDispatcher for production.
  - For best performance, we recommend forwarding the messaging connections to an HTTP 1.0 server. This results in better interactive behaviour in older Internet Explorer web browsers (pre-8.0)