I, like many web developers, have heard the edge of my ear about Flex, which in essence is the same Flash and swf file, but I didn’t really understand it. I recently learned about interesting
messaging features
from a server to a client , known as
server push . This means that you can do without periodic ajax requests, and update the data in real time (hence the notion of a stream), for example, for a chat. I will try to describe the creation and architecture of the application = browser / Flex / JBoss / BlazeDS / JMS, from which information can already go to (Spring / Hibernate / Mysql) and back.

Flex or Flash?
If Flash is focused strongly on vector graphics, then
Flex is focused on interfaces . Of course, you can create interfaces in Flash and many have done this before, understood the Action script, worked with xml, but Flex is easier in this area because it focuses on interface applications that are more multimedia than just javascript with its frameworks. Sometime I argued that HTML can be considered a programming language, completely aware that there are no variables, functions, and in general it is essentially XML. And I argued that in principle, the program in the broad sense is a sequence of actions and anything can be considered as such - a menu in a bar, a bus schedule.
Flex's “language” is XML , which can include
ActionScript . The language is essentially open (opensource) and compiled from mxml to swf using the eponymous mxmlc compiler. For more convenient development, there is a paid IDE as an Eclipse extension —
Adobe Flex Builder 3 , which allows you to quickly compile and open an application with publishing to servers with J2EE / PHP / .NET technologies or as an independent desktop AIR application. Flash / Flex methods can be associated with javascript, this allows you to rewrite only part of the application during the upgrade.
Jboss setup
We
put the latest stable version of
Jboss server version 4.2. To do this, simply drag the jboss folder from the downloaded archive into the Program Files. Jboss can be compared to an Apache server, but it is essentially more and only part of it is responsible for web processing — the popular Tomcat server for Java applications. As you have already guessed, the server application will not be in php, but in java. Unlike apache, jboss / tomcat the server immediately divides the running applications into program folders, beyond which nothing goes. According to the
training specification , the application folder is located in jboss / server / default / deploy. We go there and create our own folder, say myflex.war (with .war required)
')
Flex client
Instead of the Flex SDK c mxmlc compiler, I installed a more visual IDE Adobe Flex builder 3 with a trial period. When you add a new project to the wizard, you need to remove LiveCycle and point to the myflex.war folder. Now we write the actual code in a mixed mxml and action script format (see the bottom of the appendix). The main part of the code is the transmission of asynchronous messages. To do this, create objects of the recipient and the sender.
producer = new Producer();
producer.destination = "myTopic";
producer.addEventListener(MessageAckEvent.ACKNOWLEDGE, acknowledgeHandler);
producer.addEventListener(MessageFaultEvent.FAULT, faultHandler);
consumer = new Consumer();
consumer.destination = "myTopic";
consumer.addEventListener(MessageAckEvent.ACKNOWLEDGE, acknowledgeHandler);
consumer.addEventListener(MessageFaultEvent.FAULT, faultHandler);
consumer.addEventListener(MessageEvent.MESSAGE, messageHandler);
You can start learning Flex from the Developer Center .
BlazeDS and Messaging Service (JMS)
Download BlazeDS binary distribution. This is a compiled java-library that allows you to redirect messages from Flex to a JMS that is located on a Jboss server. Inside the downloaded archive, open the fileblazeds.war with Winrar and unpack the WEB-INF folder into our application myflex.war

Check
Check that the server is working. Create a text.html file with arbitrary content in the application and run jboss from the file bin / run.bat. The server starts for half a minute, after which you can open http: // localhost: 8080 / myflex / test.html and make sure that there is a banal job a la apache. Now when you add a project, Flex Builder will turn green, confirming availability via http.
Customization
Now you need to set up message forwarding.
To do this, you need to change five config files:- jboss / server / default / deploy / jms / jbossmq-destinations-service.xml
This file is responsible for the current JMS "message threads" by default. Each theme has its own class (mbean), which, depending on the jBoss version, inherits another class - org.jboss.jms.server.destination.TopicService for version 5 or org.jboss.mq.server.jmx.Topic for version 4.2.3 .
Create a new topic with id = myJmsTopic - jboss / server / default / deploy / myflex.war / WEB-INF / flex / services-config.xml
The main configuration of BlazeDS, which includes the other three files. Create a new channel class with id = my-streaming-http, it inherits mx.messaging.channels. StreamingHTTPChannel .
Total channels are divided by format (HTTP / AMF / RTMP), protocol types (pooling / streaming) and security level. A message from the flex-app arrives to the broker. - jboss / server / default / deploy / myflex.war / WEB-INF / flex / messaging-config.xml
Create destination (destination) with id = myTopic
In the remaining two files, proxy-config.xml and remoting-config.xml, it is enough to change the default channel from my-amf to my-streaming-http. These files are responsible for calling the java-methods with a regular http request (RPC).

Compilation
At the moment, if you compile mxml, Flex Builder will take the code you wrote from somewhere in your folder and put the swf in the Jboss folder, open the browser where you probably get an error from the flash browser: [MessagingError message = 'Destination' myTopic ' "] The thing is that when compiling the config files are not yet taken into account - because they are separate from the flex project among BlazeDS . To do this, go to the flex-project settings and add additional arguments under the Flex Compiler with the full path:
-services "C: \ Program Files \ jboss \ server \ default \ deploy \ myflex.war \ WEB-INF \ flex \ services-config.xml"
Debag
After successful compilation, I still got an internal error, which was a handler. However, I wanted to get to its details, so Flex Builder has a pleasant debugging opportunity. Is it enough to switch to another perspective mode (are everyone familiar with Eclipse?), Put a breakpoint in the right place, and when it’s done, it’s all. {context-root} in the endpoint settings, which is why it is impossible to reach the broker, because it should be available at http: // localhost: 8080 / myflex / messagebroker / streaminghttp. This is also solved in the Flex IDE project settings. The third error is browser caching of the swf file, which is why the update is not visible.
So what is next?
As I said, messages go directly through BlazeDS to JMS. JMS essentially works as a mailbox in which messages get through the channels from the producer to one or several consumers , and there are two types of “order” according to the message distribution algorithm - topic and queue. JMS, in turn, is easy to contact from a regular console / UI java application. Read also:Original →