SSM distributed Architecture e-commerce Project (v)

Source: Internet
Author: User

Functional Analysis 2.1. Technology used in the backend system

Frame: Spring + SPRINGMVC + Mybatis+dubbo

Front End: Easyui

Database: MySQL 2.2. Creating a Database

1. Install MySQL Database

2. Create a Taotao database in MySQL

3. Import Database Scripts. 2.3. Inter-system Communication

The Yu Ying Mall is SOA-based architecture, and the presentation layer and service layer are different projects. Therefore, to implement a commodity list query requires communication between the two systems.

How to implement remote communication.

1, using WebService: Inefficient, it is based on the SOAP Protocol (Http+xml). Not recommended for use in projects.

2, the use of restful forms of service: Http+json. Applications in many projects. If the service is more and more, the call relationship between service and service is complex and management is complex.

3, use Dubbo. Use the RPC protocol for remote invocation and use socket communication directly. The transfer efficiency is high, and the call relationship between the system and the number of calls can be counted. 3. Dubbo 3.1. What is Dubbo


Dubbo.io

Dubbo is a distributed service framework dedicated to providing high-performance and transparent RPC remote service invocation scenarios, and is the core framework of Alibaba SOA Service governance solution, providing 3,000,000,000+ per day support for 2,000+ services. And is widely used in Alibaba Group's member sites

With the development of the Internet, the scale of website application is expanding, the conventional vertical application architecture cannot be solved, the distributed service architecture and the mobile computing architecture are imperative, and a governance system is urgently needed to ensure an orderly evolution of the architecture.

Single Application Architecture

When site traffic is small, you need only one app to deploy all the features together to reduce deployment nodes and costs.

At this point, the data Access Framework (ORM) is the key to simplifying the effort of adding and deleting changes.

Vertical Application Architecture

As traffic increases, a single application increases the acceleration of the machine, and the application is split into several unrelated applications to improve efficiency.

At this point, the Web Framework (MVC) used to accelerate the development of front-end pages is critical.

· Distributed Service Architecture

When the vertical application is more and more, the interaction between applications inevitably, the core business extracted, as a separate service, gradually formed a stable service center, so that the front-end application can be more rapid response to changing market demand.

At this point, the Distributed Service Framework (RPC) that is used to improve business reuse and consolidation is critical.

· Flow Computing Architecture

When the service is more and more, the evaluation of capacity, and the waste of small service resources appear gradually, it is necessary to add a dispatch center to manage cluster capacity and improve cluster utilization based on access pressure.

At this point, the resource Scheduling and Governance Center (SOA) that is used to improve machine utilization is critical.

Dubbo is the management tool of the resource scheduling and governance center.

 

Dubbo is a webservice-like framework for communication between systems and can be used to count and manage the direct invocation of a service (including who called the service, how many times the call was made, and what the service is using).

3.2. Dubbo's Architecture


node Role Description:

Provider: The service provider that exposes the service.

Consumer: invokes the service consumer of the remote service.

Registry: Registration Center for service Registration and discovery.

Monitor : The monitoring center of the call times of the statistics service and the call time.

Container: The service runs the container.

Call Relationship Description:

0. The service container is responsible for starting, loading, and running the service provider.

1. Upon launch, the service provider registers its services with the registry.

2. When the service consumer starts, it subscribes to the registration center for the services it needs.

3. The registry returns the service provider address list to the consumer, and if there is a change, the registry will push the change data to the consumer based on a long connection.

4. Service consumers, from the provider address list, based on the soft load equalization algorithm, select a provider to make the call, if the call fails, then choose another call.

5. Service consumers and providers, the cumulative number of calls in memory and call time, timed to send statistics every minute to the monitoring center. 3.3. Use the method 3.3.1. Spring Configuration

Dubbo uses a full spring configuration, transparent access to the application, no API intrusion to the application, just load the Dubbo configuration with spring, and Dubbo the spring-based schema extension.

Spring configuration in a single project Local.xml

<bean id= "Xxxservice" class= "Com.xxx.XxxServiceImpl"/>

<bean id= "xxxaction" class= "Com.xxx.XxxAction" >

<property name= "Xxxservice" ref= "Xxxservice"/>

</bean>

Remote service:

On the basis of local services, you can complete the remoting by simply configuring:

Split the above local.xml configuration into two parts, place the service definition part on the service provider Remote-provider.xml, and place the service reference part in the service consumer Remote-consumer.xml.

and increase the exposure service configuration <dubbo:service> in the provider, add the Referral service configuration <dubbo:reference> in the consumer.

Service Tier Publishing services:

<!--and local services for remote service--

<bean id= "Xxxservice" class= "Com.xxx.XxxServiceImpl"/>

<!--increased exposure remote service configuration-

<dubbo:service interface= "Com.xxx.XxxService" ref= "Xxxservice"/>

Presentation Layer Invocation Service:

<!--Add reference to remote service configuration-

<dubbo:reference id= "Xxxservice" interface= "Com.xxx.XxxService"/>

<!--to use remote services like local services--

<bean id= "xxxaction" class= "Com.xxx.XxxAction" >

<property name= "Xxxservice" ref= "Xxxservice"/>

</bean>

3.4. Introduction of the registry 3.4.1. Zookeeper

The Registry is responsible for registering and locating service addresses, equivalent to directory services, where service providers and consumers interact with the registry only at startup, and the registry does not forward requests and is less stressful. The Zookeeper registry is recommended for use with dubbo-2.3.3 or later.

Zookeeper is a sub-project of Apacahe Hadoop, a tree-based directory service that supports change push, is suitable as a registry for Dubbo services, has high industrial strength, can be used in production environments, and is recommended for use.

3.4.2. Using Xshell to connect to a Linux system

For installation of Remote Tools, refer to the documentation:

When you connect to Linux, you may not be able to connect, first turn off the firewall:

Use:

Serivce command: Only at present, the system will fail once it restarts.

You can use the command:

Chkconfig iptables off permanently.


3.4.3. Installation of zookeeper:

First step: Install the JDK

Step two: Unzip the zookeeper compression pack

The third step: Copy the Conf folder under Zoo_sample.cfg, renamed to Zoo.cfg

Fourth Step: Modify the Configuration DataDir property to specify a real directory

Fifth Step:

Start zookeeper:bin/zkserver.sh Start

Close zookeeper:bin/zkserver.sh Stop

View zookeeper status: bin/zkserver.sh status

Note Turn off the firewall. 4. Framework Integration 4.1. Adding Dubbo Dependencies

Join the Dubbo related jar package. Both the service layer and the presentation layer are added.

<!--Dubbo and

<dependency>

<groupid>com.alibaba< ;/groupid>

<artifactId>dubbo</artifactId>

<!--exclude dependencies--

<exclusions >

<exclusion>

<groupId>org.springframework</groupId>

<artifactId> spring</artifactid>

</exclusion>

<exclusion>

<groupId> org.jboss.netty</groupid>

<artifactId>netty</artifactId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>org.apache.zookeeper</groupId>

<artifactId>zookeeper</artifactId>

</dependency>

<dependency>

<groupId>com.github.sgroschupf</groupId>

<artifactId>zkclient</artifactId>

</dependency>

4.2. Integration Ideas

1. DAO Layer:

MyBatis integrates spring to manage Sqlsessionfactory, Mapper proxy objects through spring. The MyBatis and spring integration packages are required to create a database connection pool from spring.

Integrated content

Correspondence Engineering

Pojo

Taotao-mangaer-pojo

Mapper Mapping File

Taotao-mangaer-dao

Mapper interface

Taotao-mangaer-dao

Sqlmapconfig.xml (Global configuration)

Taotao-manager-service

Applicationcontext-dao.xml (database connection pool)

Taotao-manager-service

2. Service Layer:

All implementation classes are managed in the spring container. and have spring management affairs; Release Dubbo Service

Integrated content

Correspondence Engineering

Service Interface

Taotao-mangaer-interface

Service Implementation Class

Taotao-mangaer-service

Applicationcontext-service.xml

Taotao-manager-service

Applicationcontext-trans.xml

Taotao-manager-service

Web. XML configuration: Configuring the Load Spring container

3. Presentation layer:

SPRINGMVC integrates the spring framework and manages the controller by SPRINGMVC; Introduction Service

Integrated content

Correspondence Engineering

Springmvc.xml

Taotao-manager-web

Controller

Taotao-manager-web

Configuration of Web. XML: Front controller, configure URL blocking form.

4.3. DAO integration 4.3.1. Creating a sqlmapconfig.xml configuration file

<?xml version= "1.0" encoding= "UTF-8"?>

<! DOCTYPE Configuration

Public "-//mybatis.org//dtd Config 3.0//en"

"Http://mybatis.org/dtd/mybatis-3-config.dtd" >

<configuration>

</configuration>

4.3.2. Spring Integration MyBatis

Create Applicationcontext-dao.xml

<?xml version= "1.0" encoding= "UTF-8"?>

<beans xmlns= "Http://www.springframework.org/schema/beans"

xmlns:context= "Http://www.springframework.org/schema/context" xmlns:p= "http://www.springframework.org/schema/p"

xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx"

Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"

xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-4.2.xsd

Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd

HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-4.2.xsd/HTTP Www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd

Http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd ">

<!--database connection pool--

<!--load configuration files--

<context:property-placeholder location= "Classpath:properties/*.properties"/>

<!--database connection pool--

<bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource"

destroy-method= "Close" >

<property name= "url" value= "${jdbc.url}"/>

<property name= "username" value= "${jdbc.username}"/>

<property name= "Password" value= "${jdbc.password}"/>

<property name= "Driverclassname" value= "${jdbc.driver}"/>

<property name= "maxactive" value= "ten"/>

<property name= "Minidle" value= "5"/>

</bean>

<!--let Spring management sqlsessionfactory use the MyBatis and spring integration packages--

<bean id= "Sqlsessionfactory" class= "Org.mybatis.spring.SqlSessionFactoryBean" >

<!--database connection pool--

<property name= "DataSource" ref= "DataSource"/>

<!--load the global configuration file for MyBatis--

<property name= "configlocation" value= "Classpath:mybatis/sql

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.

Tags Index: