Friday, May 9, 2014

Quick ColdFusion WebSockets Gotcha

I've been playing around with CF WebSockets for a few days now and have just started to work on message filtering.  Through the use of a selector I can target messages to a single client (or range of clients).  This is great, as there was a bug in the implementation of Flash Remoting and ColdFusion that broke filtering.  This meant that I had to send messages to all connected clients and filter on the client side, which as you can imagine is noisy.

Here is the Javascript I am using to subscribe and publish where ws is the ColdFusion WebSocket object created with the cfwebsocket tag:
ws.subscribe("messaging.friends", {userid: $('#userid').val(), selector: "targetuser eq '"+userselector+"'"}, friendsCallback);

...

ws.publish("messaging.friends", $("#message").val(), {targetuser: $('#userid').val()});
The simple code above subscribes to the messaging.friends subchannel using a selector that jQuery grabs from a web form.  The second line of code published a message to that channel with the same targetuser to match the selection criteria.

When I tested filtering I found that all of my messages were being delivered regardless of filtering criteria.  I had read previously that if your channel listener CFC implemented the canSendMessage() method, that this would occur.  I had removed the offending function but all of my messages continued to arrive regardless of selector criteria.

After much frustration I restarted ColdFusion and everything started working.  What seems to have happened is that when CF the Java creates classes from your CFC it picks up on changes within a method, but does not pick up that a method has been removed until the server is restarted (or if the application ends would be my guess).  Hope this saves someone some time.

3 comments:

  1. You don't have to restart CF, just the App itself. Remember CF10 added an applicationStop method to make that easier.

    ReplyDelete
  2. Thanks for the confirmation Ray. I don't think I've ever used applicationStop(), will have to work that into my reinitialization routine.

    ReplyDelete
  3. Actually, applicationstop() was introduced in CF9.

    ReplyDelete