您好,登錄后才能下訂單哦!
shard-common-entity:???公共代碼塊 shard-open-inte:????????開放接口管理 shard-eureka-7001:??????注冊中心 shard-two-provider-8001:?8001?基于兩臺庫的服務 shard-three-provider-8002:8002?基于三臺庫的服務
(1)shard-eureka-7001:????????注冊中心 (2)shard-two-provider-8001:??8001?基于兩臺庫的服務 (3)shard-three-provider-8002:8002?基于三臺庫的服務
按照順序啟動,且等一個服務完全啟動后,在啟動下一個服務,不然可能遇到一些坑。
基于Feign的調用方式 作用:基于兩臺分庫分表的數據查詢接口。鄭州治療不孕不育哪里好: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 ?*?對外開放接口 ?*/@FeignClient(value?=?"shard-provider-8001") public?interface?TwoOpenService?{ ????@RequestMapping("/selectOneByPhone/{phone}")????TableOne?selectOneByPhone(@PathVariable("phone")?String?phone)?; }
基于Feign的調用方式 作用:基于三臺分庫分表的數據存儲接口。
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;/** ?*?數據遷移服務接口 ?*/@FeignClient(value?=?"shard-provider-8002") public?interface?MoveDataService?{ ????@RequestMapping("/moveData") ????Integer?moveData?(@RequestBody?TableOne?tableOne)?; }
查詢流程圖?
代碼塊
/** ?*?8001?端口?:基于兩臺分庫分表策略的數據查詢接口 ?*/@Resourceprivate?TwoOpenService?twoOpenService?;@Overridepublic?TableOne?selectOneByPhone(String?phone)?{ ????TableOne?tableOne?=?tableOneMapper.selectOneByPhone(phone);????if?(tableOne?!=?null){ ????????LOG.info("8002?===?>>?tableOne?:"+tableOne); ????}????//?8002?服務沒有查到數據 ????if?(tableOne?==?null){????????//?調用?8001?開放的查詢接口 ????????tableOne?=?twoOpenService.selectOneByPhone(phone)?; ????????LOG.info("8001?===?>>?tableOne?:"+tableOne); ????}????return?tableOne?; }
遷移流程圖?
代碼塊
鄭州不孕不育檢查:http://wapyyk.39.net/zz3/zonghe/1d427.html
/** ?*?8002?端口開放的數據入庫接口 ?*/@Resourceprivate?MoveDataService?moveDataService?;/** ?*?掃描,并遷移數據 ?*?以?庫?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?對應的數據庫: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())?;????????????//?只演示向數據新加庫?ds_4?遷移的數據 ????????????if?(db_num.equals("ds_4")){ ????????????????i?+=?1?; ????????????????LOG.info("遷移總數數=>"?+?i?+?"=>庫位置=>"+db_num+"=>表位置=>"+tb_num+"=>數據:【"+tableOne+"】");????????????????//?掃描完成:執行新庫遷移和舊庫清理過程 ????????????????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)、訪問8002 數據查詢端口
http://127.0.0.1:8002/selectOneByPhone/phone20日志輸出:8001?服務查詢到數據8001?===?>>?tableOne?:+{tableOne}
(2)、執行8001 數據掃描遷移
http://127.0.0.1:8001/scanData
(3)、再次訪問8002 數據查詢端口
http://127.0.0.1:8002/selectOneByPhone/phone20日志輸出:8002?服務查詢到數據8002?===?>>?tableOne?:+{tableOne}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。