xml method to implement multi-channel access website architecture

PHPz
Release: 2017-04-02 11:28:19
Original
1770 people have browsed it

1. Background
In today’s websites, there are more and more access channels, and the technology is becoming more and more advanced, such as WAP, SMS, EMAIL, traditional Web, Socket, etc. If you connect to the database If it is also connected to LDAP, the space that needs to be expanded in the design must be very good to ensure that when adding new channels, no more code modifications or even code changes are required. But is it possible? It's impossible to think about it, but is there any way to better solve the perfection of this multi-channel access framework?

2. Architecture

When all the existing accesses have been used, the designers are dazzled. If it is to gather people, then these programs can be written in any way. , and it can definitely be achieved, but it will be more painful to maintain. Let’s go back to the question, how can it be achieved more perfectly? During the project team's architectural discussion, the idea of ​​routing was raised.

The core of connecting all these channels is the head of this octopusXMLRouter. The role of Router here is to communicate with all channels, realize data routing, and strive for the expansion of the system architecture. Sex and flexibility, the benefits will be many, many. It is called XMLRouter because if XML, a flexible and standardized language, is not used as a data transmission medium, the workload of the Router will also increase exponentially. Defining the XML specification will bring about future expansion. Comes with many benefits.

3. Thoughts and Patterns
The original idea of ​​XMLRouter comes from the Builder Pattern in the computer motherboard and <>, the PCI slot definition of the computer motherboard As long as the card you produce complies with the PCI standard, you can plug it into the motherboard and it will work. As for how it works inside, it has already been encapsulated. The Builder Pattern proposes to separate complex builds. , implemented step by step. XMLRouter separates these complex channels and performs them one by one.
Services idea: In order to communicate with Router, a unified interface must be defined when these channels are accessed. Here Becoming Services, as long as the program conforms to the Services specification, it can access the Router and route data.
Factory mode and Composite mode
XMLRouter will be generated using the Factory mode in the actual design, and the Router is produced by the RouterFactory. When put into use, it will be placed in the queue. The corresponding Router is taken from the queue to transfer data, receive data and return data. The Composite mode is applied.
4. XML configuration file
XML file is for Router The use in is divided into two parts. The first one is the configuration of the Router, such as:

<?xml version="1.0" ?>
<services>
   <!-- database Service -->
   <service name="database" type="database" class="com.web.service.DBService">
   <connector
       driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"
       url="jdbc:microsoft:sqlserver://192.168.0.179:1433" user="test"
       passwd="test" />
   </service>
   <!-- Web Service-->
   <service name="web" type="web" class="com.web.service.WebService" >
     <connector />
   </service>
……
</services>
Copy after login

This is the configuration file of the Router. The service node represents the channel that needs to be accessed. The service node contains the connector sub-node. The configuration of the node is distinguished according to the type. If it is database, it includes url, user, passwd, driver and other attributes. If it is socket, it includes port, maxthread and other attributes. The attribute values ​​​​can be configured according to your own definition.
Another type of XML file is the XML transaction data file, which is used to transfer data in all services. Each Service contains a corresponding XML file. For example, the format of webtrans.xml is as follows:

<?xml version="1.0" ?>
<transaction>
   <trans name="addDoc" service="database" method="insert">
     <property name="createtime" type="timestamp"/>
     <property name="creatorid" type="long"/>
     <property name="doctypeid" type="int"/>
     <property name="docstatusid" type="int"/>      
   </trans>    
</transaction>
  相应的dbtrans.xml格式如下
  <trans name="addDoc" table="TDOC_DOCS" method="insert">
     <primarykey name="docid" />    
     <set>
       <property name="createtime" type="timestamp"/>
       <property name="creatorid" type="long"/>
       <property name="doctypeid" type="int"/>
       <property name="docstatusid" type="int"/>      
     </set>
   </trans>
Copy after login

The above is the detailed content of xml method to implement multi-channel access website architecture. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!