CFLib.org – Common Function Library Project

createDestination(destname, channelId)

Last updated March 20, 2010

author

Marko Simic

Version: 1 | Requires: CF9 | Library: UtilityLib

Description:
In case you want to physically separate communication between certain groups of users, best way to do that is to create new destination and to direct messages on it. One way to do that is to define destination in messaging-config.xml or dynamically at runtime using this function. It takes 2 arguments: - destname - Destination name - channelId - Channel ID. Channel is either defined in services-config.xml or you may use createChannel method to do it at runtime

Return Values:
Returns a destination object.

Example:

local.newdestination = createDestination('classRoom_1','collyba-longpolling-amf');

Parameters:

Name Description Required
destname Destination name. Yes
channelId Channel ID. Yes

Full UDF Source:

/**
 * Creates BlazeDS destination at runtime
 * 
 * @param destname      Destination name. (Required)
 * @param channelId      Channel ID. (Required)
 * @return Returns a destination object. 
 * @author Marko Simic (marko.simic@gmail.com) 
 * @version 1, March 20, 2010 
 */
function createDestination(destname, channelId){
    var local = structNew();
    
    local.brokerClass = createObject('java','flex.messaging.MessageBroker');
    local.broker = local.brokerClass.getMessageBroker( javacast('null','') );
    local.service = local.broker.getService('message-service');
    local.destinations = local.service.getDestinations();
    
    //check if destination already exists. If it does just return it
    if (structKeyExists(local.destinations,arguments.destname)){ //check if destination already exist
        return local.destinations[arguments.destname];    
    }
    
    // Creates a ServiceAdapter instance and sets its id, sets if destination  is manageable
    local.destination = local.service.createDestination(arguments.destname);
    local.destination.createAdapter('cfgateway');
    
    local.configMap = createObject('java','flex.messaging.config.ConfigMap').init();
    local.configMap.addProperty('gatewayid',application.CFEventGatewayId);
    
    local.ss = createObject("java","flex.messaging.config.ServerSettings");
    local.ss.setAllowSubtopics(true); 
    local.ss.setSubtopicSeparator('.');
    local.ss.setDurable(false);
    
    local.destination.setServerSettings(ss);
    
    local.adapter = local.destination.getAdapter();
    
    //Initializes the adapter with the properties.
    local.adapter.initialize('cfgateway',configMap);
            
    local.destination.addChannel(arguments.channelId);
    
    //Starts the destination if its associated Service is started and if the destination is not already running. 
    local.destination.start();
    
    return local.destination;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson