Twitter: raymondcamden


Address: Lafayette, LA, USA

ColdFusion 10 WebSockets, Selectors, and canSendMessage

10-04-2012 3,216 views HTML5, ColdFusion Comments

Here is an interesting little "feature" I ran into last week while preparing for my presentation on WebSockets in ColdFusion 10. One of the features I demonstrated is called selectors. It allows you to subscribe to a channel but only receive messages that pass a boolean test. In my demo application, I listened to a channel that broadcasted the change in stocks. I used a selector to say, in code, "I only care about stocks that have a change greater than 10." This worked perfectly.

I was doing some fiddling around though when I noticed something odd. I added a CFC handler for the channel. Part of that handler had this boilerplate code in it:

canSendMessage is fired before a message is sent to any listening client. It gives you the ability to allow/deny the message to be received. This is not the same as allowPublish, which is run before the publisher (the person making the message) is allowed to broadcast on the system.

In my mind, the selector would have fired before canSendMessage. If that selector failed, then it should be as if the message never was published, at least to me, the listener.

But that wasn't the case. Because I had a simple return true in the handler, my demo application began seeing all of the messages, even those that would have failed the selector test.

So - I think this is actually a good thing... if you know it's going to happen that is. The selector data is passed to the handler. You can simply run it yourself manually. Or, you could do something else entirely. I'm not sure what. You could - possibly - log the times a message gets blocked/passed due to selectors and use it as a metric of some sort.

Anyway - just keep this in mind!

0 Comments

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead. Text wrapped in asterisks (*) will be bold and text wrapped in underscores (_) will be italicized.

Leave this field empty