March 16, 2010

BlazeDS: Creating destinations at runtime

Because it is already said a lot on this subject, I won't waste much words, but go straight to the point/code.
* Create blazeds destination at runtime. Follow SVN link to java source files for more details.
* @name hint="Destination name" 
function createDestination(destname,channelId){
 var local = structNew();
 local.brokerClass = createObject('java','flex.messaging.MessageBroker'); = local.brokerClass.getMessageBroker( javacast('null','') );
 local.service ='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]; 
 local.destination = local.service.createDestination(arguments.destname);
 // Creates a ServiceAdapter instance and sets its id, sets if destination  is manageable
 local.configMap = createObject('java','flex.messaging.config.ConfigMap').init();
 //svn: = createObject("java","flex.messaging.config.ServerSettings");;'.');;
 local.adapter = local.destination.getAdapter();
 //Initializes the adapter with the properties.

 //Starts the destination if its associated Service is started and if the destination is not already running. 
 return local.destination;
Note that I placed svn links to BlazeDS java source files. While I was working on this and especially endpoint creation, insight to these files was invaluable to me. Each method is nicely documented, so it is very easy to understand.

More on this subject:


Tony Nelson said...

I might be missing something, but I think you want to replace arguments.roomname with arguments.destname.

Marko said...

You are absolutely right. Fixed. Thank you.