Java e-Commerce project surface question (vi)

Source: Internet
Author: User
Tags script tag rabbitmq

If you insert a product, you need to insert several tables, how did you do it? Generate a product number (ID) from Redis
Save a product List
Then save the SKU table (the foreign key of this table is the ID of the commodity table)
In Qingdao has done two years of development, large and small involved in the development of three projects, one is a company's internal personnel Management system, one is a logistics project, recently done is an e-commerce project.
Throughout the project, we are using Nginx+tomcat to deploy (the interviewer may ask who the nginx was deployed to?). How is it deployed? Nginx execution process, advantages), Nginx on the one hand to do load static resources of the server, on the other hand to do reverse proxy and load balancing. Because the project needs to run in multiple environments, we use Nginx's reverse proxy to solve the problem caused by the non-unification of the different environment and the system access address.
Because the whole project realizes the function more, therefore uses the distributed architecture design, the entire project includes the backstage management system, the foreground system, the order system, the login system, the search system, the shopping cart system and so on, the advantage is to make each function module independent, reduces the coupling degree between each system, Adding or deleting a feature does not affect other function modules.
Because the project is a distributed architecture design, the modules are independent of each other, and the access path of each module is different, so when the cross-domain request data will encounter cross-domain constrained issues. For example, when the user first visit the homepage of the site, the first page will asynchronously request the background management system load the product class, this is a cross-domain constrained problem, in the past development, if in this module, we are asynchronously request data through Ajax, but Ajax does not support cross-domain, Therefore, the problem of cross-domain request data cannot be solved with Ajax. Finally, we use JSONP to solve this problem. Jsonp through the script tag src can cross-domain request characteristics, load resources, the loaded resources (through a method name data package) as a JS script parsing, define a callback function (how is it implemented?). ) to get the incoming data. We use JSONP because the compatibility of JSONP is good, and after the request is complete, we can return the result by callback way. However, one drawback of JSONP is that only get requests are supported and other types of HTTP requests such as Post are not supported.
In this way, we solved the cross-domain problem that the browser accesses the current page to load the background system data, but another problem comes, how does the other system get the data that calls back-end system? We want to be able to send HTTP requests to access background data, and we think of using httpclient to solve this problem because httpclient can use Java code to emulate the browser sending HTTP requests (how do the Get methods pass parameters?). Define the UriBuilder object, set the parameters in the UriBuilder, with the key and value, both string types, and then place the UriBuilder in the URI, after which the URI is given to the HttpGet request. Post method if data is transferred? Simulates a form submission, encapsulates the data into a list collection, and then puts the collection data into the constructed form entity, placing the form entity request into the HttpPost object. Throws an interface outward, the execution procedure is: 1, creates the HttpClient object 2, constructs the Request object post, the GET Request 3, if has the parameter, constructs the request parameter
3.1 Get
Using UriBuilder to construct request parameters
3.2 Post
Constructs the form entity and puts the form entity into the POST request object.
4. Execute the request and accept the response
5. Processing response Results

  1. Release the connection. The connection must be released regardless of the success of the execution method.
    HttpClient implementations are considered thread-safe.
    Each time the connection initiates an HTTP request, the connection is re-established (through 3 handshakes), and the connection is closed (4 waves), which consumes a lot of time, all of which we use the connection pool. If you do not use a connection pool, each connection will open a port, in case of large concurrency, the system's port resources will soon be exhausted, resulting in the inability to establish a new connection.
    Like the project in the first page of the big ads and product categories these do not need to modify the data, if the user every time to refresh the page to go to the database query, this will waste resources and increase the pressure of the database. So we want to add this data to a buffer, the user to access the time, the first to go to the cache hit, if the hit failed, then go to the database query, and then add the query to the cache of data. At present, the main cache technology has Redis and memcached, simply from the point of view of cache hit, memcached to be higher, but the gap between Redis and Memcache is not really big, but Redis provides more powerful features, read and write speed is very fast. So we chose Redis to cache the data. Redis caches data in the form of Key-value, provides a variety of data storage types (String,set,list,hash, etc.), and itself provides persistent functionality (2). You can also back up data to disk (Redis's Save command is used to create a backup of the current Redis database) to prevent data loss during Redis outages. (The updated data is periodically written to disk or the modification is written to the appended record file, and the Master-slave (master-Slave) synchronization is implemented on this basis). We are using spring and Jedis integrated client, can use Jedis to do shard cluster, solve the problem of Redis Memory Limited.
    Previously implemented login and registration is done within the same tomcat, and now the system architecture is that each system is maintained by a single team, each system is deployed separately to run a separate tomcat, so The user's login information cannot be saved to the session (multiple Tomcat sessions are not shared) (Session sharing?). ), so we need a separate system to maintain the user's login information. We do this, the user to login page login, go to the database query whether there is the user, if not prompt the user, if there is to save the user information to Redis, and generate a token to save to the cookie,
    In the back-office management system, MAVEN's multi-modular management is adopted, in which the horizontal segmentation is used (the difference between vertical and horizontal division: Vertical: The function module is clear, the level is not clear, the code reuse is poor. Level: Clear hierarchy, high code reuse, independent maintenance. ), layered development of layers, the benefits of which are high code reuse, clear hierarchy, easy to maintain independently. The system internal interface call adopts HttpClient, the interface provides a RESTful interface definition (a software architecture style, design style rather than standard, but provides a set of design principles and constraints), notification mechanism between systems using MQ, the implementation of RABBITMQ , using the message mechanism of RABBITMQ's message subscription mode; Deployment aspect, adopt nginx+tomcat pattern, in which nginx function is to do reverse proxy, load balance, on the other hand is to do the static resources such as Picture server;
    In this project I mainly responsible for the background management module, mainly to achieve commodity management and Commodity specification parameter management, the commodity and commodity specifications for CRUD operations. In the implementation of the foreground call to the background data, in order to achieve the system calls, then used the HttpClient technology to implement this function, in the background to provide the interface needed to call. (HttpClient Introduction, working principle, advantages and disadvantages). If the product is operated in the background, in order to synchronize the foreground data with the background data, we use the RABBITMQ Message Queuing mechanism to realize the product synchronization function (RABBITMQ Introduction, working principle, advantages and disadvantages);
    In this project, I also participated in the development of the shopping cart module. In the development of this module, we consider the member in the two cases without login and login to add items to the shopping cart, backstage how to save the product information.
    In the user's Product Details page Click to add to the shopping cart, we used a login blocker to determine whether the user login;
    If you do not log in, save the product information to a cookie, and then persist the product to the database when the user logs in, but given the size of the cookie, and the more data stored in the cookie, the response speed will be affected. We decided to use Redis to cache the product information (Redis Introduction, rationale, Pros and cons) of the user in a non-logged-in state, and set the cache lifetime in Redis (how do I do that?). ), if the user does not log in within the specified time, the data will be deleted automatically. If the user logs in within the specified time, the data will be synchronized to the database through the RABBITMQ Message Queuing mechanism;

Java e-Commerce project surface question (vi)

Related Article

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.