Tuesday, April 24, 2012

ColdFusion WebSocket Part5 : Publish Workflow

Channel Listener CFC is the Control Panel for your ColdFusion WebSocket application.
All the data that is published in your channel passes through your Channel Listener CFC. In this blog post I will  explain the various Channel Listener functions that are called when a data is published.

A Channel Listener CFC is associated with a  channel. All the sub-channels of that channel also will be controlled by the same Channel Listener CFC.To see sample code on how to associate  a channel  with a Channel Listener CFC check my previous blog entry
Consider a scenarios where you have four clients C1 , C2, C3 and C4.

Consider a case where News is the main channel. Sports and Politics are sub-channels of News. Tennis is a sub-channel of sports.
C1 is subscribed to News
C2 is subscribed to News.Sports
C3 is subscribed to News.Sports.Tennis
C4 is subscribed to News.Politics.



Whenever data has to be published over the channel, four Channel Listener functions are called internally.

  1. AllowPublish - Verifies if the publisher has the right to publish. If this function returns true, the message is eligible to be published.
  2. BeforePublish- This method can be used to format the message.
  3. CanSendMessage- This method is executed for each client. This function validates if each of the clients is eligible to receive the message.
  4. BeforeSendMessage-This method is executed for each client. This method can be used to format the message differently for each client.
These functions are called in a predefined order and a developer or user has no control over the order of function call. Developers can customize the logic inside these channel Listener functions to implement any business logic.

See the following diagram which shows the flow of data as well as the order of function calls during a data publish.





























The above diagram also explains how different clients receive data.
For example C2 - subscribed to  News sports will receive any data that comes on News.Sports and its sub-channels(In this case News.Sports.Tennis).
C2 will not receive data on any sibling channel(News.Politics) or parent channel(News).
Also you can see that C1 subscribed to News will receive data on all channels.

For more reference and code samples on ColdFusion WebSocket see the previous entries in this ColdFusion WebSocket blog series



2 comments:

  1. Great input, thank you very much for taking the time to expose this type of technology.

    ReplyDelete
  2. WebSocket is a web technology providing for bi-directional, full-duplex communications channels over a single TCP connection, and WebSocket support is new in ColdFusion 10. it is designed to be implemented in web browsers and web servers, but it can be used by any client or server application.

    Custom Coldfusion Development Company India

    ReplyDelete