您好,登錄后才能下訂單哦!
shard-common-entity:???公共代碼塊 shard-open-inte:????????開(kāi)放接口管理 shard-eureka-7001:??????注冊(cè)中心 shard-two-provider-8001:?8001?基于兩臺(tái)庫(kù)的服務(wù) shard-three-provider-8002:8002?基于三臺(tái)庫(kù)的服務(wù)
(1)shard-eureka-7001:????????注冊(cè)中心 (2)shard-two-provider-8001:??8001?基于兩臺(tái)庫(kù)的服務(wù) (3)shard-three-provider-8002:8002?基于三臺(tái)庫(kù)的服務(wù)
按照順序啟動(dòng),且等一個(gè)服務(wù)完全啟動(dòng)后,在啟動(dòng)下一個(gè)服務(wù),不然可能遇到一些坑。
基于Feign的調(diào)用方式 作用:基于兩臺(tái)分庫(kù)分表的數(shù)據(jù)查詢(xún)接口。鄭州治療不孕不育哪里好: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 ?*?對(duì)外開(kāi)放接口 ?*/@FeignClient(value?=?"shard-provider-8001") public?interface?TwoOpenService?{ ????@RequestMapping("/selectOneByPhone/{phone}")????TableOne?selectOneByPhone(@PathVariable("phone")?String?phone)?; }
基于Feign的調(diào)用方式 作用:基于三臺(tái)分庫(kù)分表的數(shù)據(jù)存儲(chǔ)接口。
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;/** ?*?數(shù)據(jù)遷移服務(wù)接口 ?*/@FeignClient(value?=?"shard-provider-8002") public?interface?MoveDataService?{ ????@RequestMapping("/moveData") ????Integer?moveData?(@RequestBody?TableOne?tableOne)?; }
查詢(xún)流程圖?
代碼塊
/** ?*?8001?端口?:基于兩臺(tái)分庫(kù)分表策略的數(shù)據(jù)查詢(xún)接口 ?*/@Resourceprivate?TwoOpenService?twoOpenService?;@Overridepublic?TableOne?selectOneByPhone(String?phone)?{ ????TableOne?tableOne?=?tableOneMapper.selectOneByPhone(phone);????if?(tableOne?!=?null){ ????????LOG.info("8002?===?>>?tableOne?:"+tableOne); ????}????//?8002?服務(wù)沒(méi)有查到數(shù)據(jù) ????if?(tableOne?==?null){????????//?調(diào)用?8001?開(kāi)放的查詢(xún)接口 ????????tableOne?=?twoOpenService.selectOneByPhone(phone)?; ????????LOG.info("8001?===?>>?tableOne?:"+tableOne); ????}????return?tableOne?; }
遷移流程圖?
代碼塊
鄭州不孕不育檢查:http://wapyyk.39.net/zz3/zonghe/1d427.html
/** ?*?8002?端口開(kāi)放的數(shù)據(jù)入庫(kù)接口 ?*/@Resourceprivate?MoveDataService?moveDataService?;/** ?*?掃描,并遷移數(shù)據(jù) ?*?以?庫(kù)?db_2?的?table_one_1?表為例 ?*/@Overridepublic?void?scanDataRun()?{ ????String?sql?=?"SELECT?id,phone,back_one?backOne,back_two?backTwo,back_three?backThree?FROM?table_one_1"?;????//?dataTwoTemplate?對(duì)應(yīng)的數(shù)據(jù)庫(kù):ds_2 ????List<TableOne>?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())?;????????????//?只演示向數(shù)據(jù)新加庫(kù)?ds_4?遷移的數(shù)據(jù) ????????????if?(db_num.equals("ds_4")){ ????????????????i?+=?1?; ????????????????LOG.info("遷移總數(shù)數(shù)=>"?+?i?+?"=>庫(kù)位置=>"+db_num+"=>表位置=>"+tb_num+"=>數(shù)據(jù):【"+tableOne+"】");????????????????//?掃描完成:執(zhí)行新庫(kù)遷移和舊庫(kù)清理過(guò)程 ????????????????moveDataService.moveData(tableOne)?;????????????????//?dataTwoTemplate.update("DELETE?FROM?table_one_1?WHERE?id=??AND?phone=?",tableOne.getId(),tableOne.getPhone()); ????????????} ????????} ????} }
https://www.jianshu.com/p/fc56f6221728
(1)、訪問(wèn)8002 數(shù)據(jù)查詢(xún)端口
http://127.0.0.1:8002/selectOneByPhone/phone20日志輸出:8001?服務(wù)查詢(xún)到數(shù)據(jù)8001?===?>>?tableOne?:+{tableOne}
(2)、執(zhí)行8001 數(shù)據(jù)掃描遷移
http://127.0.0.1:8001/scanData
(3)、再次訪問(wèn)8002 數(shù)據(jù)查詢(xún)端口
http://127.0.0.1:8002/selectOneByPhone/phone20日志輸出:8002?服務(wù)查詢(xún)到數(shù)據(jù)8002?===?>>?tableOne?:+{tableOne}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。