Last active
December 10, 2015 02:19
-
-
Save rjattrill/4366725 to your computer and use it in GitHub Desktop.
Flex STOMP Receiver. Uses http://code.google.com/p/as3-stomp/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<s:Group | |
xmlns:fx="http://ns.adobe.com/mxml/2009" | |
xmlns:s="library://ns.adobe.com/flex/spark" xmlns:stomp="org.codehaus.stomp.*" | |
creationComplete="init()" | |
> | |
<fx:Script> | |
<![CDATA[ | |
import org.codehaus.stomp.Stomp; | |
import org.codehaus.stomp.event.MessageEvent; | |
import org.codehaus.stomp.headers.*; | |
[Bindable] | |
public var message:String; | |
[Bindable] | |
public var topic:String = 'workflow.parameter.62'; | |
private var destination:String = "/topic/" + topic; | |
public var stomp:Stomp = new Stomp(); | |
public var mqHost:String; | |
private function init():void { | |
destination = "/topic/" + topic; | |
trace("Adding event listener"); | |
stomp.addEventListener(MessageEvent.MESSAGE, handleMessages); | |
mqHost = getHostName(); | |
trace("Making Stomp connection"); | |
var ch:ConnectHeaders = new ConnectHeaders(); | |
ch.login = "guest"; | |
ch.passcode = "guest" | |
stomp.connect(mqHost, 61613, ch); | |
stomp.subscribe(destination); | |
} | |
public function stompConnect():void { | |
stomp.unsubscribe(destination); | |
destination = "/topic/" + topic; | |
trace("Resubscribing on destination: " + destination); | |
stomp.subscribe(destination); | |
} | |
private function handleMessages(event:MessageEvent):void { | |
var byteArray:ByteArray = event.message.body; | |
var message:String = byteArray.toString(); | |
trace("Received message " + message); | |
this.message = message; | |
} | |
public function getHostName():String { | |
var hostUrl:String = parentApplication.url; | |
trace("Host Url: " + hostUrl); | |
var re:RegExp = /http:\/\/(\w*):\d*/; | |
var result:Array = re.exec(hostUrl); | |
trace(result); | |
var hostName:String = result[1]; | |
trace("ActiveMQ Hostname = " + hostName); | |
return hostName; | |
} | |
]]> | |
</fx:Script> | |
<s:VGroup width="100%" height="100%" top="10" left="10"> | |
<s:HGroup> | |
<s:Label text="Topic:"/> | |
<s:TextInput text="@{topic}" width="200" valueCommit="stompConnect()"/> | |
</s:HGroup> | |
<s:HGroup> | |
<s:Label text="Message:"/> | |
<s:TextInput id="messageTextInput" width="200" text="{message}"/> | |
</s:HGroup> | |
</s:VGroup> | |
</s:Group> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above works with ActiveMQ with STOMP protocol enabled. Make sure that you have a flashpolicy server (publishing a socket policy file, allowing access to your STOMP message queue) for this to work.