Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center /

Data push from .NET to Flex with MSMQ

by Sunil A. Nair

Sunil A. Nair
  • sunilanair.wordpress.com

Content

  • Project overview
  • Project setup
  • Developing the .NET code
  • Developing the Flex Code
  • Running the Example
  • Where to go from here

Created

8 August 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
.NET configuration Flex RIA WebORB

Requirements

Prerequisite knowledge

Intermediate level knowledge of Flex, .NET, and IIS are required to make the most of this article.  Some knowledge of MSMQ will also be helpful.

User level

Intermediate

Required products

  • Flash Builder (Download trial)

Sample files

  • data-push.zip

Additional required other products

  • Microsoft .NET Framework 2.0 or later
  • WebORB for .NET v4.0 (or later)
  • Microsoft Message Queue (MSMQ)

There are several message queuing options available to push data from the server side to Flex clients. The option you choose will depend upon the server side technology you use. If your server-side is Microsoft .NET, then you can use Microsoft Message Queuing (MSMQ), a free queuing mechanism included with most Windows operating systems, to push data from .NET to various clients. This allows applications running on separate servers and processes to communicate with one another. MSMQ enables publish-subscribe message exchange paradigms for Windows/.NET environments. This article will show you how to route messages from MSMQ to Flex clients, enabling data push from .NET to Flex.

Project overview

This article walks through the process of creating a simple real-time stock quoting application that uses WebORB for .NET and MSMQ to enable communication between a .NET back end and a Flex client. The sample project contains a simple server-side page, which is used to enter company stock information. The Flex client has a data grid, which displays the stock information in real-time as it is received via MSMQ.

WebORB for .NET is used for publish-subscribe messaging, enabling messaging destinations to be connected with MSMQ queues. WebORB for .NET acts as a proxy between the queue and the subscribed client (see Figure 1).

Figure 1. Data push from the server side to the client via MSMQ and WebORB for .NET.
Figure 1. Data push from the server side to the client via MSMQ and WebORB for .NET.

Project setup

Before you begin coding you'll need to set up MSMQ and WebORB for .NET.

MSMQ setup

On your Windows computer, open the Control Panel and then open Computer Management in Administrative Tools. Expand Services and Applications and look for a folder named Message Queuing. If you don't find such a folder, you will need to install MSMQ for this example to work properly. MSMQ can be installed via the Control Panel. For more information on installing it on different Windows operating systems see Installing Message Queuing (MSMQ) on MSDN.

Once installed, you will need to create a queue.

  1. Open Control Panel and then open Administrative Tools > Computer Management.
  2. Expand Message Queuing and you will see Private Queues.
  3. Right-click to create a new non-transactional Private Queue (see Figure 2). Type weborb-testqueue as the Queue Name. Click OK.
Figure 2. Creating a new private queue.
Figure 2. Creating a new private queue.
  1. Right-click on the newly created queue and select Properties. Type WebORB MessageQueue for Flex as the label (see Figure 3). Click OK.
Figure 3. Setting the queue label.
Figure 3. Setting the queue label.

The queue name and label name are important parameters that are used when configuring WebORB.

Configuring WebORB

Download and install WebORB for .NET if you haven't already done so. The MSMQ exposed through WebORB acts as a messaging destination for an application that needs to listen for messages in the queue. To configure the queue as a destination for the Flex client, you'll need to edit WebORB's messaging-config.xml file located under the [WEBORB-INSTALL]/WEB-INF/flex directory.

  1. Open messaging-config.xml and add the following XML:
<destination channels="weborb-rtmp" id="webmsmq"> <properties> <msmq> <path>.\private$\weborb-testqueue</path> <deliverPastMessages>-1</deliverPastMessages> <BasePriority>0</BasePriority> <Category>00000000-0000-0000-0000-000000000000</Category> <Label>WebORB MessageQueue for Flex</Label> <MaximumQueueSize>4294967295</MaximumQueueSize> <UseJournalQueue>false</UseJournalQueue> <MaximumJournalSize>4294967295</MaximumJournalSize> </msmq> <message-service-handler> Weborb.Messaging.PubSub.Msmq.MessagingServiceHandler </message-service-handler> </properties> <channels> <channel ref="weborb-rtmp"/> </channels> </destination>
  1. Save your changes.

The purpose of each node is explained in the messaging-config.xml file.

In the sample project, the .NET web page targets the queue named weborb-testqueue. The value of the id attribute of the destination node (in this case, webmsmq) specifies the messaging destination. This same value will be used for the destination property in the consumer—that is, the Flex client—as well.

Developing the .NET code

The .NET code will act as an MSMQ producer. The web page consists of a form into which values are typed. Upon clicking the Send button on the ASPX page, SendMsg() is invoked

public void SendMSG() { StockVO objVo = new StockVO { Company = txtCompanyName.Text,LastSales = Convert.ToDouble(txtLastSales.Text), ShareVolume = Convert.ToDouble(txtShareVolume.Text), change = Convert.ToInt64(txtChange.Text) }; MessageQueue objQueue = new MessageQueue("FormatName:DIRECT=OS:.\\private$\\weborb-testqueue"); BinaryMessageFormatter objformat = new BinaryMessageFormatter(); objformat.TypeFormat = System.Runtime.Serialization.Formatters.FormatterTypeStyle.TypesAlways; objQueue.Formatter = objformat; objQueue.DefaultPropertiesToSend.Recoverable = true; Message objMsg = new Message(objVo, objformat); objMsg.Label = "test"; objQueue.Send(objMsg); }

All the values from the form are passed as properties of StockVO, which is the value object. The objQueue instance of MessageQueue targets the queue and sends objVO (the StockVO instance) as a message to the target queue.

Developing the Flex Code

The Flex application acts as the consumer.

Pinging WebORB

For the consumer to receive messages, it is important to know whether the WebORB messaging service is up and running. So, on the creationComplete event of the application the PingFromWeborb() method is invoked. This method returns a string as the result, which is displayed in an alert. When the result event fires, you know that the messaging service is running. If the ping was unsuccessful, then the fault event handler will display the error details in an alert. To check what went wrong, you can use an HTTP sniffer tool to see if the WebORB gateway was called. To investigate further, debug the Flex application as well as the Global.asax file on the server side. Global.asax, which is located inside the WebORB folder, is where the messaging server is started.

private function pingWeborb():void { var ro:RemoteObject = new RemoteObject("GenericDestination"); ro.source = "ping"; ro.endpoint = "http://localhost/weborb4/weborb.aspx"; ro.PingFromWebORB.addEventListener(ResultEvent.RESULT, onPingResult); ro.PingFromWebORB.addEventListener(FaultEvent.FAULT, onPingFault); ro.PingFromWebORB(); }

Registering as a consumer

Upon clicking the Connect button, the Flex client will register itself as a consumer. The WeborbConsumer class of the WebORB Client API enables the Flex client to subscribe to a messaging destination. The value of the destination property should correspond to the value of the destination attribute in the messaging-config.xml file. The subscribe() method subscribes the Flex client to the queue.

public function doConnect():void { consumer = new Consumer(); consumer.destination = "webmsmq"; consumer.addEventListener( MessageEvent.MESSAGE, receivedMessage ); consumer.addEventListener( MessageAckEvent.ACKNOWLEDGE, receivedACK); consumer.subscribe(); currentState = "connectedState"; }

Receiving messages

To get messages from the queue, the instance of the consumer listens to MessageEvent.MESSAGE. Its message handler will receive the message from the queue.

public function receivedMessage( event:MessageEvent ):void { stock = StockVO( event.message.body ); dataCollection.addItemAt(stock, 0); }

The messages received are cast to complex types and added to an ArrayCollection object, which populates the data in a data grid.

Running the Example

Follow the steps below to run the sample application:

  1. If you have not already done so, create an MSMQ queue and configure WebORB for .NET as described in the Project setup section.
  2. Open Microsoft Internet Information Services (IIS), create a virtual directory, and deploy the .NET project from the sample files into the virtual directory. In your browser, navigate to the default.aspx file on your server; you should see the MSMQ Producer form.
  3. Locate ShareData.dll in the bin folder of the sample .NET project and deploy it inside the WebORB bin folder, for example: [WEBORB HOME]\bin.
  4. Import the sample Flex project into Flash Builder. Add WebORB.swc, which is located [WEBORB HOME]\weborbassets\wdm, to the Flex project Build Path library.
  5. Add the following as an additional compiler argument:
-services "pathname_in_your_machine_to_the_WebORB_directory/WEB-INF/flex/weborb-services-config.xml"
  1. Run the application and wait for the application to ping the WebORB server. If the ping is successful, it will show an Alert that says "Hello from web.orb".
  2. Now Click Connect and you should see an acknowledgement message.
  3. Type some values in the form on the .NET page and click Send. The message will be sent to the queue.
  4. Observe the Flex application, which should update the data grid with the data that you typed in the .NET page (see Figure 4).
Figure 4. The .NET page (left) and the Flex client (right).
Figure 4. The .NET page (left) and the Flex client (right).

If you encounter any problems, the first troubleshooting step is to make sure that the .NET page is sending the messages to the queue.

  1. In Control Panel, open Administrative Tools > Computer Management > Message Queuing > Private Queues.
  2. Then open the queue that you configured earlier and check the queue messages. If the messages are not available, it could be that you do not have permission to read and write to the queue.
  3. Go to the Security tab in the Properties section of the queue and assign full permission to your user name (the one that you used to log in).

If you have messages in the queue and you're still not getting data pushed to the client, the messaging server might be down. For the messaging server to start, an ASP.NET request must be sent to the application first. For more information on how to do this, see RTMP Server Overview in the WebORB for .NET User Guide.

Where to go from here

Now that you have the application up and running, you can run more than one instance of the Flex client to see that the data pushed from MSMQ through WebORB is routed to multiple Flex clients.

You may also want to learn more about conditional message delivery, which you can use to control the delivery of messages based on conditional logic in the message delivery chain. For more details, see Data Push from MSMQ to Flex.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Forging an enterprise Flex team
  • Flex mobile development tips and tricks – Part 1: Data handling
  • Flex and Maven with Flexmojos – Part 2: The apprentice
  • Flex mobile development tips and tricks—Part 4: Creating an alert popup and other skinnable popups
  • Migrating Flex 3 applications to Flex 4.5 – Part 2: Beginning migration of the Dashboard application to Flex 4.5
  • Flex mobile performance checklist
  • Migrating Flex 3 applications to Flex 4.5 – Part 4: Using Spark Panel, List, DataGrid, and VGroup components and adding custom skins and states
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 3: Introducing Spark components and simple skins
  • Flex mobile development tips and tricks – Part 5: Using mobile view and tab transitions

Tutorials & Samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Flex User Forum

More
07/25/2011 Flash Player Debug Issues - Safari 5.1 & Chrome 13
04/22/2012 Loader png - wrong color values in BitmapData
04/22/2012 HTTPService and crossdomain.xml doesn't work as expected
04/23/2012 Memory related crashes in Flex application

Flex Cookbook

More
04/06/2012 How to detect screen resize with a SkinnableComponent
02/29/2012 Embed Stage3D content inside Flex application components
02/15/2012 Custom WorkFlow Component
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement