Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Fabric3 supports exposing channels over websockets and long-pooling using binding.web. This enables clients such as browsers to send and receive SCA events in a variety of formats, including JSON and XSM. The web binding is built on the Atmosphere library (http://atmosphere.java.net/).

The samples distribution contains examples of using websockets to expose event streams to browser clients. following shows how to expose a channel over websockets or long-pooling using the web binding:

Code Block
xml
xml

<composite xmlns:f3="urn:fabric3.org"...>

    <channel name="ChatChannel">
        <f3:binding.web/>
    </channel>

    <component name="ChatListener">
        <implementation.java class="org.fabric3.samples.chat.ChatListener"/>
        <consumer name="chatChannel" source="ChatChannel"/>
    </component>

</composite>

The above will expose the chat channel at http://<runtime ip>:<port>/channels/ChatChannel. When a client such as a browser connects to the endpoint, the connection will automatically be upgraded to websockets or use long-pooling depending on the client's capabilities.

Info

Channels endpoints configured with the web binding are available over HTTP (or HTTPS if the runtime has it enabled) under the /channels path.

Connecting a consumer to the channel is done using the standard SCA eventing programming model:

Code Block
java
java

@Scope("COMPOSITE")
public class ChatListener {

    @Consumer("chatChannel")
    public void onMessage(Message message) {
        System.out.println(message.getName() + ": " + message.getMessage());
    }
}

When deployed in a cluster, events sent from browser clients to a channel will be replicated by default to all channel instances in a zone. To disable replication, set the @replicate attribute to false:

Code Block
xml
xml

<channel name="MyChannel">

...


   <f3:binding.web replicate="false"/>

...


</channel>

The Fabric3 Samples distribution contains examples of using websockets.