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 Restore this Version View Page History

« Previous Version 4 Current »

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 following shows how to expose a channel over websockets or long-pooling using the web binding:

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

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:

@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:

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

The Fabric3 Samples distribution contains examples of using websockets.

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.