In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Project structure 1. Engineering structure
2. Module naming shard-common-entity: common code block shard-open-inte: open interface management shard-eureka-7001: registry shard-two-provider-8001: 8001 Services based on two libraries shard-three-provider-8002:8002 based on three libraries 3, code dependency structure
4. Project launch order (1) shard-eureka-7001: registry (2) shard-two-provider-8001: 8001 services based on two libraries (3) shard-three-provider-8002:8002 services based on three libraries
Start in sequence, and after one service is fully started, start the next service, otherwise you may encounter some pits.
2. Core code block 1, 8001 services provide an external service
Function of calling mode based on Feign: data query interface based on two sub-libraries and sub-tables. How to treat infertility in Zhengzhou: http://www.zzfkyy120.com/
Import org.springframework.cloud.netflix.feign.FeignClient;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import shard.jdbc.common.entity.TableOne;/** * shard-two-provider-8001 * Open Interface * / @ FeignClient (value = "shard-provider-8001") public interface TwoOpenService {@ RequestMapping ("/ selectOneByPhone/ {phone}") TableOne selectOneByPhone (@ PathVariable ("phone") String phone) } 2. 8002 service provides an external service
The function of calling mode based on Feign: the data storage interface based on three sub-libraries and sub-tables.
Import org.springframework.cloud.netflix.feign.FeignClient;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import shard.jdbc.common.entity.TableOne;/** * data migration service interface * / @ FeignClient (value = "shard-provider-8002") public interface MoveDataService {@ RequestMapping ("/ moveData") Integer moveData (@ RequestBody TableOne tableOne); 3. Query interface based on 8002 service data
Query flow chart
Code block
/ * Port 8001: data query interface * / @ Resourceprivate TwoOpenService twoOpenService based on two sub-databases and sub-table policies; @ Overridepublic TableOne selectOneByPhone (String phone) {TableOne tableOne = tableOneMapper.selectOneByPhone (phone); if (tableOne! = null) {LOG.info ("8002 = = > > tableOne:" + tableOne) } / / 8002 service did not find data if (tableOne = = null) {/ / call 8001 open query interface tableOne = twoOpenService.selectOneByPhone (phone); LOG.info ("8001 = = > > tableOne:" + tableOne);} return tableOne;} 4, scan migration code based on 8001 data
Migration flow chart
Code block
Infertility examination in Zhengzhou: http://wapyyk.39.net/zz3/zonghe/1d427.html
/ * * data storage interface open on port 8002 * / @ Resourceprivate MoveDataService moveDataService; / * scan and migrate data * take the table_one_1 table of library db_2 as an example * / @ Overridepublic void scanDataRun () {String sql = "SELECT id,phone,back_one backOne,back_two backTwo,back_three backThree FROM table_one_1" / / dataTwoTemplate corresponding database: ds_2 List tableOneList = dataTwoTemplate.query (sql,new Object [] {}, new BeanPropertyRowMapper (TableOne.class)); if (tableOneList! = null & & tableOneList.size () > 0) {int I = 0; for (TableOne tableOne: tableOneList) {String db_num = HashUtil.moveDb (tableOne.getPhone ()); String tb_num = HashUtil.moveTable (tableOne.getPhone ()) / only demonstrate data if (db_num.equals ("ds_4")) {I + = 1; LOG.info ("Total number of migrations = >" + I + "= > library location = >" + db_num+ "= > table location = >" + tb_num+ "= > data: [" + tableOne+ "]") / / scan completed: perform new library migration and old library cleaning process moveDataService.moveData (tableOne); / / dataTwoTemplate.update ("DELETE FROM table_one_1 WHERE id=?" AND phone=? ", tableOne.getId (), tableOne.getPhone ();} III. Demonstrate the execution process.
Https://www.jianshu.com/p/fc56f6221728
1. Project flow chart
2. Test execution process
(1) access to 8002 data query port
Http://127.0.0.1:8002/selectOneByPhone/phone20 log output: 8001 service query data 8001 = = > > tableOne: + {tableOne}
(2) perform 8001 data scan migration
Http://127.0.0.1:8001/scanData
(3) access the 8002 data query port again
Http://127.0.0.1:8002/selectOneByPhone/phone20 log output: 8002 service query data 8002 = = > > tableOne: + {tableOne}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
In fact, there is just one more;! This habit can't be changed.
© 2024 shulou.com SLNews company. All rights reserved.