Link to home
Start Free TrialLog in
Avatar of blue44
blue44Flag for United States of America

asked on

How to incorporate Consumer functionatliy into Cairngorm?

Hi,

I'm converting a Flex application to Cairngorm and haven't been able to figure out what to do with the Consumer calls.  I've read through all the documentation and included CairngormEnterprise.swc into my build and added the Consumer instance to my ServiceLocator just as with any other http or RPC call.  The error I keep on getting is this:

Only one ServiceLocator instance can be instantiated

I'm guessing this is because I'm instantiating EnterpriseServiceLocator a long with ServiceLocator but I don't what else to do since the getConsumer() method is only in the EnterpriseServiceLcoator object.

Any help would be greatly appreciated.  I've included both my delegate and ServiceLocator classes.

Thanks!
blue
package control.delegates
{
	import com.adobe.cairngorm.business.ServiceLocator;
	
	import mx.messaging.Consumer;
	import mx.messaging.events.MessageEvent;
	import mx.rpc.IResponder;
	import mx.messaging.events.MessageFaultEvent;
	import com.adobe.cairngorm.enterprise.business.EnterpriseServiceLocator;
		
	public class ReceiveMessageDelegate
	{
		private var _responder:IResponder;
		private var _service:Consumer;
		
		public function ReceiveMessageDelegate(r:IResponder)
		{     		
			_service = EnterpriseServiceLocator.getInstance().getConsumer("receiveMessageEvent");
			_responder = r;
			_service.addEventListener(MessageEvent.MESSAGE, _responder.result);
			_service.addEventListener(MessageFaultEvent.FAULT, _responder.fault);
		}
		
		// Subscribes to the feed.
		public function subscribe():void
		{  
			_service.subscribe();
		}
		
		// Unsubscribes to the feed.
		public function unsubscribe():void
		{  
			_service.unsubscribe();
		}
	}
 
<!-------------- ServiceLocator ------------------>
 
<?xml version="1.0" encoding="utf-8"?>
<rds:ServiceLocator xmlns:rds="com.adobe.cairngorm.business.*"
	xmlns:mx="http://www.adobe.com/2006/mxml">
	
	<mx:Script>
		<![CDATA[
			
			import model.ModelLocator;
			
			[Bindable]
			private var __model:ModelLocator=ModelLocator.getInstance();
			
		]]>
	</mx:Script>
	
	<mx:Consumer id="receiveMessageEvent" destination="ColdFusionGateway" />
		
</rds:ServiceLocator>
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of blue44
blue44
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dkoleba
dkoleba

Nice work blue44. Could you give an example of how you changed you code to accommodate this?
Avatar of blue44

ASKER

Well, it's been over a year so I had to go back and review the code.  All I did was manually add both the Cairngorm.swc and CairngormEnterprise.swc to the lib directory in a Flex Project (assuming you're utilizing Flex Builder).  Then, if you go to your project properties > Flex Build Path, you'll find both under the lib directory.  Hope this helps!