Windows Azure AppFabric Introductory Teaching series (VI): Message buffer initial experience

Source: Internet
Author: User
Keywords nbsp we as follows
Tags .mall applied click code console create created debug




This article is the sixth article in the introductory teaching of Windows Azure AppFabric. This article will introduce a very useful feature-messagebuffer in service bus. This feature is similar to the queue Storage, as a small, temporary information buffer that can be applied to a variety of scenarios. In this case, we'll simply simulate the order system: order, view orders, and process orders.


Preconditions

For the following tutorials to work smoothly, make sure that the software or components below are installed:

· Microsoft. NET Framework 3.5 SP1

· Microsoft Visual Studio 2008 SP1 (or adjective)

· 8 ">appfabric SDK

· Windows Azure Platform Training kit-december Update (sample code)

Please make sure you have some WCF programming experience, if not, please browse here for a quick preliminary understanding of WCF.

Finally, make sure that you have created a AppFabric project and a service namespace. Please refer to here.

Code:

1. From Windows Azure Platform training kit-december Update (sample code) installation directory C:\WindowsAzurePlatformKit\Labs\IntroServiceBus\ Source\ex05-messagebuffer\end\cs (default path) to find the complete Mssagebuffer program code. Double-click MssageBuffer.sln to open the project.

2. For easy debugging, open the Orderpeek project, the Program.cs of the Orderprocessor and Ordersubmitter projects, and change the corresponding section to the following code in the first article of this tutorial:

Console.Write ("Your Service Namespace:");

String servicenamespace = "{Your service namespace}";//console.readline ();

Console.Write ("Your issuer Name:");

String issuername = "{Your issuer name}"; Console.ReadLine ();

Console.Write ("Your issuer Secret:");

String Issuersecret = "{Your issuer secret}"; Console.ReadLine ();

Authentication:

3. The Orderpeek project creates a messagebuffer that holds the order and can see if there are any outstanding orders.

The Ordersubmitter project generates new orders and puts them in the messagebuffer created by Orderpeek.

The Orderprocessor project handles orders in Messagebuffer.

4. Right-click the Orderpeek item, Debug->start new instance.

5. Right-click the Ordersubmitter item, Debug->start new instance. Follow the prompts to enter string information:

For example:

I. Nails [Return]

Ii. 1 Hammer [Enter]

Iii. 1 wrench [Enter]

The following figure:



6. We see that the Orderpeek instance will see if the Messagebuffer has an unhandled order, and the first order is not processed. The following figure:


7. Right-click the orderprocessor item, Debug->start new instance. Orderprocessor will see if there are any orders, poll and print out the order content. The following figure:

Finally, we see that the orders sent in step 5th have been processed.

8. We can increase the number of instances of orderprocessor (consumer roles) to meet the high load requirements when there are many message requests to be processed in Messagebuffer. Of course, we can also have multiple instances of Ordersubmitter (producer roles).

Analysis:

9. Let's start by looking at how to create a messagebuffer. Open the Program.cs of the Orderpeek project, as shown below:


9.1 Creating endpoint credentials (endpoint credentials)

9.2 Create Messagebuffer Mount URI

9.3 Create Messagebufferpolicy. Messagebufferpolicy is the necessary parameter to create a messagebuffer. The following are Messagebufferpolicy attributes and their meanings.

Messagebufferpolicy Property
Description

Expireafter
The lifecycle of message buffer

MaxMessageCount
Message buffer can hold the maximum number of message before the overflow policy is activated.

Overflowpolicy
The behavior when the message overflows. Currently, the only behavior currently available is to reject the new message and send an error to the sender.

Transportprotection
Transmission protection refers to the level of security that the end-to-end must use.

Authorization
Specifies the type of authorization required to send and receive, optionally "notrequired", "Required", "requiredtoreceive", and "Requiredtosend".

Call the Ensuremessagebufferexists function to ensure that the Messagebuffer is created successfully.

Ensuremessagebufferexists internal implementation of the following figure:



If a messagebuffer already exists, the call Getmessagebuffer returns the Messagebuffer that already exists. If not, Getmessagebuffer throws an exception and then calls Createmessagebuffer to create a new messagebuffer.

10. After creating the Messagebuffer, let's look at how to send the message to the Messagebuffer. Open the Program.cs of the Ordersubmitter project.


10.1 Get already created good messagebuffer.

10.2 Because different scenarios require different objects to be sent, different objects need to be converted to a message object that Messagebuffer can handle. The System.ServiceModel assembly provides us with an Easy-to-use Typedmessageconverter class to convert objects to message.

10.3 After converting an object to a message, you can simply call the Send method to send it.

More than 10.4 is messagebuffer a higher level of encapsulation, interested readers can study the AppFabric SDK installation directory: Windows Azure platform AppFabric sdk\v1.0\samples\ SERVICEBUS\EXPLORINGFEATURES\MESSAGEBUFFER\PLAINHTTP\CS35 plainhttp Project. It demonstrates how the rest protocol operates MESSAGEBUFFER,REST protocols that are independent of language and operating systems, so languages such as Java can be used on non-Windows systems to use Messagebuffer.


11. Similarly, the code to process the message is very simple.


11.1 Call Ensuremessagebufferexisits because our Oderpeek project has created Messagebuffer, so this step we'll get the Messagebuffer reference.

11.2 Initialize Typedmessageconverter.

11.3 Get the first message.

11.4 Converts the message with Typedmessageconverter to the object that needs to be processed.

11.5ProcessOrder is the process.

11.6 polls the next message.

12. For more Messagebuffer applications refer to the AppFabric SDK installation directory: Windows Azure platform AppFabric sdk\v1.0\samples\servicebus\ Items in the Exploringfeatures\messagebuffer\ directory.

This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/azurechina/archive/2010/05/27/5629210.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.