vue2純前端對接海康威視攝像頭實現實時視頻預覽

vue2純前端對接海康威視攝像頭實現實時視頻預覽

  • 一、環境準備
  • 二、代碼集成
    • 1.1 準備webrtcstreamer.js,粘貼即用,不用做任何修改
    • 1.2 封裝視頻組件,在需要視頻的地方引入此封裝的視頻組件即可,也是粘貼即用,注意其中import的webrtcstreamer.js的地址替換為自己的
    • 1.3 以上完成之后,需要觀看視頻的本地PC設備啟動webrtc-streamer插件

實現實時對海康威視攝像頭進行取流的大致思路:攝像頭做端口映射(安裝攝像頭的師傅一般都會),做了映射之后就可以通過IP+端口的形式在瀏覽器中進行攝像頭的實時瀏覽,這種是海康威視自己就帶有的方式,不能嵌入到自研的系統,視頻流畫面實現嵌入自研系統,需要在滿足以上的前提下,使用webrtc-streamer進行推流,然后在vue2中進行接流,渲染到頁面中

一、環境準備

需要具備的前提條件,設備可在網頁端進行瀏覽,且做以下設置
登錄進行設置
在這里插入圖片描述

設置視頻編碼格式
設置RTSP協議端口
至此攝像頭設置已完成,接下來需要獲取攝像頭設備所在IP的rtsp鏈接,海康攝像頭的rtsp鏈接獲取見官方說明:海康威視攝像頭取流說明
可以使用VLC取流軟件進行驗證rtsp鏈接是否是通的VLC官方下載地址
VLC官網
打開網絡串流
輸入取流地址
在這里插入圖片描述
至此準備工作就完成了,接下來就是敲代碼進行集成階段了

二、代碼集成

1.1 準備webrtcstreamer.js,粘貼即用,不用做任何修改

var WebRtcStreamer = (function() {/** * Interface with WebRTC-streamer API* @constructor* @param {string} videoElement - id of the video element tag* @param {string} srvurl -  url of webrtc-streamer (default is current location)
*/
var WebRtcStreamer = function WebRtcStreamer (videoElement, srvurl) {if (typeof videoElement === "string") {this.videoElement = document.getElementById(videoElement);} else {this.videoElement = videoElement;}this.srvurl           = srvurl || location.protocol+"//"+window.location.hostname+":"+window.location.port;this.pc               = null;    this.mediaConstraints = { offerToReceiveAudio: true, offerToReceiveVideo: true };this.iceServers = null;this.earlyCandidates = [];
}WebRtcStreamer.prototype._handleHttpErrors = function (response) {if (!response.ok) {throw Error(response.statusText);}return response;
}/** * Connect a WebRTC Stream to videoElement * @param {string} videourl - id of WebRTC video stream* @param {string} audiourl - id of WebRTC audio stream* @param {string} options  -  options of WebRTC call* @param {string} stream   -  local stream to send* @param {string} prefmime -  prefered mime
*/
WebRtcStreamer.prototype.connect = function(videourl, audiourl, options, localstream, prefmime) {this.disconnect();// getIceServers is not already receivedif (!this.iceServers) {console.log("Get IceServers");fetch(this.srvurl + "/api/getIceServers").then(this._handleHttpErrors).then( (response) => (response.json()) ).then( (response) =>  this.onReceiveGetIceServers(response, videourl, audiourl, options, localstream, prefmime)).catch( (error) => this.onError("getIceServers " + error ))} else {this.onReceiveGetIceServers(this.iceServers, videourl, audiourl, options, localstream, prefmime);}
}/** * Disconnect a WebRTC Stream and clear videoElement source
*/
WebRtcStreamer.prototype.disconnect = function() {		if (this.videoElement?.srcObject) {this.videoElement.srcObject.getTracks().forEach(track => {track.stop()this.videoElement.srcObject.removeTrack(track);});}if (this.pc) {fetch(this.srvurl + "/api/hangup?peerid=" + this.pc.peerid).then(this._handleHttpErrors).catch( (error) => this.onError("hangup " + error ))try {this.pc.close();}catch (e) {console.log ("Failure close peer connection:" + e);}this.pc = null;}
}    WebRtcStreamer.prototype.filterPreferredCodec = function(sdp, prefmime) {const lines = sdp.split('\n');const [prefkind, prefcodec] = prefmime.toLowerCase().split('/');let currentMediaType = null;let sdpSections = [];let currentSection = [];// Group lines into sectionslines.forEach(line => {if (line.startsWith('m=')) {if (currentSection.length) {sdpSections.push(currentSection);}currentSection = [line];} else {currentSection.push(line);}});sdpSections.push(currentSection);// Process each sectionconst processedSections = sdpSections.map(section => {const firstLine = section[0];if (!firstLine.startsWith('m=' + prefkind)) {return section.join('\n');}// Get payload types for preferred codecconst rtpLines = section.filter(line => line.startsWith('a=rtpmap:'));const preferredPayloads = rtpLines.filter(line => line.toLowerCase().includes(prefcodec)).map(line => line.split(':')[1].split(' ')[0]);if (preferredPayloads.length === 0) {return section.join('\n');}// Modify m= line to only include preferred payloadsconst mLine = firstLine.split(' ');const newMLine = [...mLine.slice(0,3), ...preferredPayloads].join(' ');// Filter related attributesconst filteredLines = section.filter(line => {if (line === firstLine) return false;if (line.startsWith('a=rtpmap:')) {return preferredPayloads.some(payload => line.startsWith(`a=rtpmap:${payload}`));}if (line.startsWith('a=fmtp:') || line.startsWith('a=rtcp-fb:')) {return preferredPayloads.some(payload => line.startsWith(`a=${line.split(':')[0].split('a=')[1]}:${payload}`));}return true;});return [newMLine, ...filteredLines].join('\n');});return processedSections.join('\n');
}/*
* GetIceServers callback
*/
WebRtcStreamer.prototype.onReceiveGetIceServers = function(iceServers, videourl, audiourl, options, stream, prefmime) {this.iceServers       = iceServers;this.pcConfig         = iceServers || {"iceServers": [] };try {            this.createPeerConnection();let callurl = this.srvurl + "/api/call?peerid=" + this.pc.peerid + "&url=" + encodeURIComponent(videourl);if (audiourl) {callurl += "&audiourl="+encodeURIComponent(audiourl);}if (options) {callurl += "&options="+encodeURIComponent(options);}if (stream) {this.pc.addStream(stream);}// clear early candidatesthis.earlyCandidates.length = 0;	// create Offerthis.pc.createOffer(this.mediaConstraints).then((sessionDescription) => {console.log("Create offer:" + JSON.stringify(sessionDescription));console.log(`video codecs:${Array.from(new Set(RTCRtpReceiver.getCapabilities("video")?.codecs?.map(codec => codec.mimeType)))}`)console.log(`audio codecs:${Array.from(new Set(RTCRtpReceiver.getCapabilities("audio")?.codecs?.map(codec => codec.mimeType)))}`)if (prefmime != undefined) {//set prefered codeclet [prefkind] = prefmime.split('/');if (prefkind != "video" && prefkind != "audio") {prefkind = "video";prefmime = prefkind + "/" + prefmime;}console.log("sdp:" + sessionDescription.sdp);sessionDescription.sdp = this.filterPreferredCodec(sessionDescription.sdp, prefmime);console.log("sdp:" + sessionDescription.sdp);}this.pc.setLocalDescription(sessionDescription).then(() => {fetch(callurl, { method: "POST", body: JSON.stringify(sessionDescription) }).then(this._handleHttpErrors).then( (response) => (response.json()) ).catch( (error) => this.onError("call " + error )).then( (response) =>  this.onReceiveCall(response) ).catch( (error) => this.onError("call " + error ))}, (error) => {console.log ("setLocalDescription error:" + JSON.stringify(error)); });}, (error) => { alert("Create offer error:" + JSON.stringify(error));});} catch (e) {this.disconnect();alert("connect error: " + e);}	    
}WebRtcStreamer.prototype.getIceCandidate = function() {fetch(this.srvurl + "/api/getIceCandidate?peerid=" + this.pc.peerid).then(this._handleHttpErrors).then( (response) => (response.json()) ).then( (response) =>  this.onReceiveCandidate(response)).catch( (error) => this.onError("getIceCandidate " + error ))
}/*
* create RTCPeerConnection 
*/
WebRtcStreamer.prototype.createPeerConnection = function() {console.log("createPeerConnection  config: " + JSON.stringify(this.pcConfig));this.pc = new RTCPeerConnection(this.pcConfig);let pc = this.pc;pc.peerid = Math.random();			pc.onicecandidate = (evt) => this.onIceCandidate(evt);pc.onaddstream    = (evt) => this.onAddStream(evt);pc.oniceconnectionstatechange = (evt) => {  console.log("oniceconnectionstatechange  state: " + pc.iceConnectionState);if (this.videoElement) {if (pc.iceConnectionState === "connected") {this.videoElement.style.opacity = "1.0";}			else if (pc.iceConnectionState === "disconnected") {this.videoElement.style.opacity = "0.25";}			else if ( (pc.iceConnectionState === "failed") || (pc.iceConnectionState === "closed") )  {this.videoElement.style.opacity = "0.5";} else if (pc.iceConnectionState === "new") {this.getIceCandidate();}}}pc.ondatachannel = function(evt) {  console.log("remote datachannel created:"+JSON.stringify(evt));evt.channel.onopen = function () {console.log("remote datachannel open");this.send("remote channel openned");}evt.channel.onmessage = function (event) {console.log("remote datachannel recv:"+JSON.stringify(event.data));}}try {let dataChannel = pc.createDataChannel("ClientDataChannel");dataChannel.onopen = function() {console.log("local datachannel open");this.send("local channel openned");}dataChannel.onmessage = function(evt) {console.log("local datachannel recv:"+JSON.stringify(evt.data));}} catch (e) {console.log("Cannor create datachannel error: " + e);}	console.log("Created RTCPeerConnnection with config: " + JSON.stringify(this.pcConfig) );return pc;
}/*
* RTCPeerConnection IceCandidate callback
*/
WebRtcStreamer.prototype.onIceCandidate = function (event) {if (event.candidate) {if (this.pc.currentRemoteDescription)  {this.addIceCandidate(this.pc.peerid, event.candidate);					} else {this.earlyCandidates.push(event.candidate);}} else {console.log("End of candidates.");}
}WebRtcStreamer.prototype.addIceCandidate = function(peerid, candidate) {fetch(this.srvurl + "/api/addIceCandidate?peerid="+peerid, { method: "POST", body: JSON.stringify(candidate) }).then(this._handleHttpErrors).then( (response) => (response.json()) ).then( (response) =>  {console.log("addIceCandidate ok:" + response)}).catch( (error) => this.onError("addIceCandidate " + error ))
}/*
* RTCPeerConnection AddTrack callback
*/
WebRtcStreamer.prototype.onAddStream = function(event) {console.log("Remote track added:" +  JSON.stringify(event));this.videoElement.srcObject = event.stream;let promise = this.videoElement.play();if (promise !== undefined) {promise.catch((error) => {console.warn("error:"+error);this.videoElement.setAttribute("controls", true);});}
}/*
* AJAX /call callback
*/
WebRtcStreamer.prototype.onReceiveCall = function(dataJson) {console.log("offer: " + JSON.stringify(dataJson));let descr = new RTCSessionDescription(dataJson);this.pc.setRemoteDescription(descr).then(() =>  { console.log ("setRemoteDescription ok");while (this.earlyCandidates.length) {let candidate = this.earlyCandidates.shift();this.addIceCandidate(this.pc.peerid, candidate);				}this.getIceCandidate()}, (error) => { console.log ("setRemoteDescription error:" + JSON.stringify(error)); });
}	/*
* AJAX /getIceCandidate callback
*/
WebRtcStreamer.prototype.onReceiveCandidate = function(dataJson) {console.log("candidate: " + JSON.stringify(dataJson));if (dataJson) {for (let i=0; i<dataJson.length; i++) {let candidate = new RTCIceCandidate(dataJson[i]);console.log("Adding ICE candidate :" + JSON.stringify(candidate) );this.pc.addIceCandidate(candidate).then( () =>      { console.log ("addIceCandidate OK"); }, (error) => { console.log ("addIceCandidate error:" + JSON.stringify(error)); } );}this.pc.addIceCandidate();}
}/*
* AJAX callback for Error
*/
WebRtcStreamer.prototype.onError = function(status) {console.log("onError:" + status);
}return WebRtcStreamer;
})();if (typeof window !== 'undefined' && typeof window.document !== 'undefined') {window.WebRtcStreamer = WebRtcStreamer;
}
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {module.exports = WebRtcStreamer;
}

1.2 封裝視頻組件,在需要視頻的地方引入此封裝的視頻組件即可,也是粘貼即用,注意其中import的webrtcstreamer.js的地址替換為自己的

<template><div class="rtsp_video_container"><div v-if="videoUrls.length === 1" class="rtsp_video single-video"><video :id="'video_0'" controls autoPlay muted width="100%" height="100%" style="object-fit: fill"></video></div><div v-if="videoUrls.length >1" v-for="(videoUrl, index) in videoUrls" :key="index" class="rtsp_video"><video :id="'video_' + index" controls autoPlay muted width="100%" height="100%" style="object-fit: fill"></video></div></div>
</template><script>import WebRtcStreamer from '../untils/webrtcstreamer'; // 注意此處替換為webrtcstreamer.js所在的路徑export default {name: 'RtspVideo',props: {videoUrls: {type: Array,required: true,}},data() {return {cameraIp: 'localhost:8000', // 這里的IP固定為本地,不要修改,是用來與本地的webrtc-streamer插件進行通訊的,見文章1.3webRtcServers: [],  // 存儲 WebRtcStreamer 實例};},mounted() {this.initializeStreams();},watch: {// 監聽 videoUrls 或 cameraIp 的變化,重新初始化流videoUrls: {handler(newUrls, oldUrls) {if (newUrls.length !== oldUrls.length || !this.isSameArray(newUrls, oldUrls)) {this.resetStreams();this.initializeStreams();}},deep: true,},cameraIp(newIp, oldIp) {if (newIp !== oldIp) {this.resetStreams();this.initializeStreams();}}},methods: {// 初始化視頻流連接initializeStreams() {if (this.webRtcServers.length === 0) {this.videoUrls.forEach((videoUrl, index) => {const videoElement = document.getElementById(`video_${index}`);const webRtcServer = new WebRtcStreamer(videoElement, `http://${this.cameraIp}`);this.webRtcServers.push(webRtcServer);webRtcServer.connect(videoUrl, null, 'rtptransport=tcp', null);});}},// 檢查新舊數組是否相同isSameArray(arr1, arr2) {return arr1.length === arr2.length && arr1.every((value, index) => value === arr2[index]);},// 清除 WebRtcStreamer 實例resetStreams() {this.webRtcServers.forEach((webRtcServer) => {if (webRtcServer) {webRtcServer.disconnect(); // 斷開連接}});this.webRtcServers = []; // 清空實例},},beforeDestroy() {this.resetStreams();  // 頁面銷毀時清理 WebRtcStreamer 實例,避免內存泄漏},
};
</script><style lang="less" scoped>
.rtsp_video_container {display: flex;flex-wrap: wrap;gap: 10px;justify-content: space-between;
}.rtsp_video {flex: 1 1 48%;height: 225px;max-width: 48%;background: #000;border-radius: 8px;overflow: hidden;
}.single-video {flex: 1 1 100%;height: 100%;max-width: 100%;background: #000;
}video {width: 100%;height: 100%;object-fit: cover;
}
</style>

父組件中進行此視頻組件的引用示例:

<template><div style="margin-top: 10px;width: 100%;height: 100%;"><rtsp-video :videoUrls="selectedUrls" :key="selectedUrls.join(',')"></rtsp-video></div>
</template>import RtspVideo from "../views/video";
components: {RtspVideo
}data(){return{selectedUrls: ['rtsp://user:password@x.x.x.x:xxxx/Streaming/Channels/101','rtsp://user:password@x.x.x.x:xxxx/Streaming/Channels/201'],}      
}

1.3 以上完成之后,需要觀看視頻的本地PC設備啟動webrtc-streamer插件

webrtc-streamer插件下載webrtc-streamer
下載圖中的版本,標題1.1中對應的js版本就是此版本
下載解壓完成之后,其中的exe和js是配套的,插件腳本在webrtc-streamer-v0.8.13-dirty-Windows-AMD64-Release\bin目錄下,對應的webrtcstreamer.js在webrtc-streamer-v0.8.13-dirty-Windows-AMD64-Release\share\webrtc-streamer\html目錄下,只需要webrtc-streamer.exe和webrtcstreamer.js即可,也可以直接用博主在上面提供的,切記一定要配套,不然可能畫面取不出。

實現效果圖見下:
在這里插入圖片描述

至此海康威視實時視頻預覽功能已完成,寫作不易,如果對您有幫助,懇請保留一個贊。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/98069.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/98069.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/98069.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Android 設置禁止截圖和禁止長截圖

1.禁止截圖 在 Activity 代碼中 , 可以在調用 setContentView 函數之前 ,為 Window 窗口對象 設置 LayoutParams.FLAG_SECURE 標志位 , 可以禁止對本界面進行截屏 ,Window 窗口對象 , 可通過 getWindow 方法獲取 ,核心代碼如下 :getWindow().setFlags(LayoutParams.FLAG_SECUR…

AR 巡檢在工業的應用|阿法龍XR云平臺

AR 巡檢的應用覆蓋電力、石油化工、智能制造、軌道交通、冶金等對設備可靠性和安全性要求極高的行業&#xff0c;具體場景包括&#xff1a;電力行業變電站內設備的狀態檢查&#xff1a;通過 AR 眼鏡掃描設備&#xff0c;實時顯示設備額定參數、歷史故障記錄、實時傳感器數據&am…

【C++】STL詳解(七)—stack和queue的介紹及使用

? 堅持用 清晰易懂的圖解 代碼語言&#xff0c; 讓每個知識點都 簡單直觀 &#xff01; &#x1f680; 個人主頁 &#xff1a;不呆頭 CSDN &#x1f331; 代碼倉庫 &#xff1a;不呆頭 Gitee &#x1f4cc; 專欄系列 &#xff1a; &#x1f4d6; 《C語言》&#x1f9e9; 《…

深度學習周報(9.8~9.14)

目錄 摘要 Abstract 1 LSTM相關網絡總結與對比 1.1 理論總結 1.2 代碼運行對比 2 量子計算入門 3 總結 摘要 本周首先總結了LSTM、Bi-LSTM與GRU的區別與優缺點&#xff0c;對比了三者實戰的代碼與效果&#xff0c;還另外拓展了一些循環神經網絡變體&#xff08;包括窺視…

Quat 四元數庫使用教程:應用場景概述

基礎概念 四元數是一個包含四個元素的數組 [x, y, z, w]&#xff0c;其中 x,y,z表示虛部&#xff0c;w 表示實部。單位四元數常用于表示3D空間中的旋轉。 1. 創建和初始化函數 create() - 創建單位四元數 應用場景&#xff1a;初始化一個新的四元數對象&#xff0c;通常作為其他…

【Java后端】Spring Boot 多模塊項目實戰:從零搭建父工程與子模塊

如何用 Spring Boot 搭建一個父工程 (Parent Project)&#xff0c;并在其中包含多個子模塊 (Module)&#xff0c;適合企業級項目或者需要分模塊管理的場景。Spring Boot 多模塊項目實戰&#xff1a;從零搭建父工程與子模塊在日常開發中&#xff0c;我們經常會遇到這樣的需求&am…

企業級AI會議系統技術實現:快鷺如何用AI重構會議全流程

摘要 本文深度解析快鷺AI會議系統的核心技術架構&#xff0c;重點探討其在語音識別、自然語言處理、數據集成和安全防護等方面的技術實現。通過對比傳統會議系統的技術痛點&#xff0c;分析快鷺AI如何通過技術創新實現會議籌備時間減少67%、數據調取速度提升100倍的顯著效果。…

【CSS學習筆記3】css特性

1css三大特性 1.1層疊性&#xff1a;就近原則&#xff0c;最新定義的樣式 1.2繼承性&#xff1a;子標簽集成父標簽的樣式&#xff0c;如文本和字號 行高的繼承&#xff1a;不加單位指的是當前文字大小的倍數 body {font: 12px/1.5 Microsoft YaHei;color: #be1313;} div {…

[C語言]常見排序算法①

1.排序的概念及常見的排序算法排序在咱們日常生活中十分的常見&#xff0c;就好比是網上購物的時候通常能夠選擇按照什么排序&#xff0c;比如價格、評論數量、銷量等。那么接下來咱們就來了解一些關于排序的概念。排序&#xff1a;所謂排序&#xff0c;就是使一串記錄&#xf…

文獻閱讀筆記:RS電子戰測試與測量技術文檔

信息來源&#xff1a;羅德與施瓦茨&#xff08;Rohde & Schwarz&#xff09;公司關于電子戰&#xff08;Electronic Warfare, EW&#xff09;測試與測量解決方案專業技術文檔。 該文檔由臺灣地區應用工程師Mike Wu撰寫&#xff0c;核心圍繞電子戰基礎、雷達系統、實戰應用及…

別再糾結 Postman 和 Apifox 了!這款開源神器讓 API 測試更簡單

別再糾結 Postman 和 Apifox 了&#xff01;這款開源神器讓 API 測試更簡單&#x1f525; 作為一名開發者&#xff0c;你是否還在為選擇 API 測試工具而糾結&#xff1f;Postman 太重、Apifox 要聯網、付費功能限制多&#xff1f;今天給大家推薦一款完全免費的開源替代方案 ——…

微調神器LLaMA-Factory官方保姆級教程來了,從環境搭建到模型訓練評估全覆蓋

1. 項目背景 開源大模型如LLaMA&#xff0c;Qwen&#xff0c;Baichuan等主要都是使用通用數據進行訓練而來&#xff0c;其對于不同下游的使用場景和垂直領域的效果有待進一步提升&#xff0c;衍生出了微調訓練相關的需求&#xff0c;包含預訓練&#xff08;pt&#xff09;&…

創建其他服務器賬號

? 在 /home74 下創建新用戶的完整步驟1. 創建用戶并指定 home 目錄和 shellsudo useradd -m -d /home74/USERNAME -s /bin/bash USERNAME-m&#xff1a;自動創建目錄并復制 /etc/skel 默認配置文件&#xff08;.bashrc 等&#xff09;。-d&#xff1a;指定用戶 home 路徑&…

【WebGIS】Vue3使用 VueLeaflet + 天地圖 搭建地圖可視化平臺(基礎用法)

初始化 創建項目 nodejs 18.0.6npm 9.5.1 引入地圖服務 VueLeaflet GitHub - vue-leaflet/vue-leaflet&#xff1a; vue-leaflet 與 vue3 兼容 Vue Leaflet (vue2-leaflet) package.josn安裝版本 直接添加四個依賴 {// ..."scripts": {// ...},"depen…

OpenCV 開發 -- 圖像閾值處理

文章目錄[toc]1 基本概念2 簡單閾值處理cv2.threshold3 自適應閾值處理cv2.adaptiveThreshold更多精彩內容&#x1f449;內容導航 &#x1f448;&#x1f449;OpenCV開發 &#x1f448;1 基本概念 圖像閾值處理&#xff08;Thresholding&#xff09;是圖像處理中的一種基本技術…

單串口服務器-工業級串口聯網解決方案

在工業自動化、智能電網、環境監測等領域&#xff0c;傳統串口設備&#xff08;如PLC、傳感器、儀表等&#xff09;的網絡化升級需求日益增長。博為智能單串口服務器憑借高性能硬件架構、多協議支持和工業級可靠性&#xff0c;為RS485設備提供穩定、高效的TCP/IP網絡接入能力&a…

第 9 篇:深入淺出學 Java 語言(JDK8 版)—— 吃透泛型機制,筑牢 Java 類型安全防線

簡介&#xff1a;聚焦 Java 泛型這一“類型安全保障”核心技術&#xff0c;從泛型解決的核心痛點&#xff08;非泛型代碼的運行時類型錯誤、強制類型轉換冗余&#xff09;切入&#xff0c;詳解泛型的本質&#xff08;參數化類型&#xff09;、核心用法&#xff08;泛型類/接口/…

MySQL和Redis的數據一致性問題與業界常見解法

一、為什么會出現數據不一致&#xff1f; 根本原因在于&#xff1a;這是一個涉及兩個獨立存儲系統的數據更新操作&#xff0c;它無法被包裝成一個原子操作&#xff08;分布式事務&#xff09;。更新數據庫和更新緩存是兩個獨立的步驟&#xff0c;無論在代碼中如何排列這兩個步驟…

coolshell文章閱讀摘抄

coolshell文章閱讀摘抄打好基礎學好英語限制你的不是其它人&#xff0c;也不是環境&#xff0c;而是自己Java打好基礎 程序語言&#xff1a;語言的原理&#xff0c;類庫的實現&#xff0c;編程技術&#xff08;并發、異步等&#xff09;&#xff0c;編程范式&#xff0c;設計模…

數據庫造神計劃第六天---增刪改查(CRUD)(2)

&#x1f525;個人主頁&#xff1a;尋星探路 &#x1f3ac;作者簡介&#xff1a;Java研發方向學習者 &#x1f4d6;個人專欄&#xff1a;《從青銅到王者&#xff0c;就差這講數據結構&#xff01;&#xff01;&#xff01;》、 《JAVA&#xff08;SE&#xff09;----如此簡單&a…