Asynchronous service framework

Source: Internet
Author: User
Tags msmq

We will talk about performance optimization in many different aspects, such as good coding habits, maximizing server performance and reducing download traffic. However, what we are talking about today is performance optimization at a larger granularity, of course, the asynchronous service framework is not only used to optimize performance, but can be considered for all scenarios that require asynchronous, offline, delayed operations, and high-cost operations.

This asynchronous service framework uses some core technologies, such as WCF, MSMQ, and IOC. For a brief introduction, WCF is used for different applications.ProgramFor inter-device communication, WCF is a good SOA application technology; MSMQ is a queue service that provides a complete set of asynchronous offline solutions. Here we do not directly use MSMQ, instead, it is applied through the encapsulation of WCF. The netmsmqbinding of WCF is a good packaging application for MSMQ. The IOC container is used to support the development and calling of different application plug-ins.

Let's first preview several features of the asynchronous service framework. We will have a deeper understanding in the subsequent explanations:

1. Optimized Performance: distributed operations with high concurrency, high time consumption, and poor real-time performance
2. Easy Scalability: by deploying more services to support more message streams
3. Group Management: reasonable distribution of message streams
4. Plug-In mode: develop independent plug-ins for different applications

I. Next, let's take a look at the framework of the basic system. There are many different services in the framework, but we will not list them here to make the presentation clearer.

# The figure shows the necessary technologies used: WCF, MSMQ, IOC, and group management.

# Simple process: client --> group management --> call information (select node) + internal identity parameter-> WCF (MSMQ) --> receive service --> select plug-in Application --> execute business logic

# Group Management: client-> sourename --> group management --> service node list under the Group --> select the corresponding service node

We say that services can be deployed into many different service nodes, so the client must know the service nodes and communication protocols that should be called before calling the service, therefore, the client obtains the corresponding service group from the Group Management Based on the sourcename configured for its own calls, select nodes and protocols with better performance load from the node list of the Service Group with different data priorities for future calls. Invoker_groups.xml

# MSMQ: client --> message to be processed and call id --> client queue-> WCF (MSMQ) --> server Queue --> processing ......

After the client inserts a message into the client queue, the call is completed. This operation takes a very short time, and the rest of the operations are completed by the WCF (MSMQ) and backend services, therefore, the response time is very fast. If a time-consuming and high-cost operation is diverted, this method can effectively improve the response performance and avoid thread congestion.

If a network fault cannot be connected to the server, the client queue will not be lost until the network fault is rectified and the transmission can be restored automatically.

If the service on the server end is upgraded and the service is stopped, the queue on the server end will not be lost until the service is started normally and the queue processing will be automatically restored.

The number of concurrent requests can be controlled under the processing of WCF for the server-side queue's outbound operations. By controlling the number of concurrent requests, the external capability of a single service node can be effectively controlled.

# Plug-In mode and dynamic call: source --> servicename, version --> icallservice interface --> actual Processor --> processing ......

The source object has two important parameters: servicename and version, which are used to determine which icallservice interface to call.

 

Ii. Client example: You can call the services in the asynchronous service framework through simple configuration.

1. Reference Components: dmedia. fetion. Framework. servicemodel. dll, dmedia. fetion. invokeservice. Contract. dll

2. Add Configuration:

<! -- Localhost, online, functest->

<Add key = "iserviceinvoker. runtimestate" value = "localhost"/>
<Add key = "iserviceinvoker. configurationfilepath" value = "Configuration | *"/>

Where:

Runtimestate indicates the current running status, localhost indicates the local call, online indicates the online production environment, and functest indicates the functional testing environment.

Configurationfilepath indicates the storage path of the group configuration file. Configuration | * indicates that the configuration directory under the root directory of the application is preferentially selected. If the directory exists, it is placed under the root directory, if you want to customize the app_data storage path, you can write it as app_data | Configuration | *

3. Call example:

# Method 1: serviceinvokermanager. Invoke ("sourcename", "Identity ");

# Method 2: serviceinvokermanager. createiserviceinvoker ("sourcename"). Invoke (
Source. fromconfiguration ("sourcename"). setclientip ("127.0.0.1 "),
"Identity ");

# Method 3: serviceinvokermanager. createiserviceinvoker ("sourcename ")
. Invoke () => source. fromconfiguration ("sourcename"). setclientip ("127.0.0.1"), "Identity ");

# Standard method:

Iserviceinvoker = serviceinvokermanager. createiserviceinvoker ("sourcename ");
If (iserviceinvoker! = NULL)
{
Source source = source. fromconfiguration ("sourcename"). setclientip ("127.0.0.1 ");
If (source! = NULL)
{
Iserviceinvoker. Invoke (source, "ABC ");
}
}

Iii. Plug-in development

1. Implement the icallservice Interface

2. Add to container icallservice. config

3. Update the group configuration (invoker_groups.xml) and assign a service node to the client.

4. More services

1. ilogservice internal logs

2. Fault Tolerance Service (retry queue and dead message records)

3. asynchronous error logging

4. asynchronous performance count

5. callback service functions (external interface encapsulation)

6 ,......

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.