前後端灰度發布解決方案

2021-10-04 01:25:32 字數 3005 閱讀 9198

io.jmnarloch

ribbon-discovery-filter-spring-cloud-starter

2.1.0

//內部通過threadlocal實現

final ribbonfiltercontext context = ribbonfiltercontextholder.getcurrentcontext();

//獲取在第二步存放的「version」 (ribbonfiltercontextholder.getcurrentcontext().add("version", version.tostring())

可以在這裡獲取

final set> attributes = collections.unmodifiableset(context.getattributes().entryset());

//查詢eureka中服務的元資料,也就是第一步中設定的metadata

final mapmetadata = server.getinstanceinfo().getmetadata();

//匹配versoin

return metadata.entryset().containsall(attributes);

public class customconcurrencystrategy extends hystrixconcurrencystrategy 

hystrixcommandexecutionhook commandexecutionhook =

hystrixplugins.getinstance().getcommandexecutionhook();

hystrixeventnotifier eventnotifier = hystrixplugins.getinstance().geteventnotifier();

hystrixmetricspublisher metricspublisher = hystrixplugins.getinstance().getmetricspublisher();

hystrixpropertiesstrategy propertiesstrategy =

hystrixplugins.getinstance().getpropertiesstrategy();

this.logcurrentstateofhystrixplugins(eventnotifier, metricspublisher, propertiesstrategy);

hystrixplugins.reset();

hystrixplugins.getinstance().registerconcurrencystrategy(this);

hystrixplugins.getinstance().registercommandexecutionhook(commandexecutionhook);

hystrixplugins.getinstance().registereventnotifier(eventnotifier);

hystrixplugins.getinstance().registermetricspublisher(metricspublisher);

hystrixplugins.getinstance().registerpropertiesstrategy(propertiesstrategy);

} catch (exception e)

}private void logcurrentstateofhystrixplugins(hystrixeventnotifier eventnotifier,

hystrixmetricspublisher metricspublisher, hystrixpropertiesstrategy propertiesstrategy)

}@override

public callablewrapcallable(callablecallable)

@override

public threadpoolexecutor getthreadpool(hystrixthreadpoolkey threadpoolkey,

hystrixpropertycorepoolsize, hystrixpropertymaximumpoolsize,

hystrixpropertykeepalivetime, timeunit unit, blockingqueueworkqueue)

@override

public threadpoolexecutor getthreadpool(hystrixthreadpoolkey threadpoolkey,

hystrixthreadpoolproperties threadpoolproperties)

@override

public blockingqueuegetblockingqueue(int maxqueuesize)

@override

public hystrixrequestvariablegetrequestvariable(hystrixrequestvariablelifecyclerv)

private final callabletarget;

private final requestattributes requestattributes;

private final mapribbonattributes;

this.target = target;

this.requestattributes = requestattributes;

this.ribbonattributes = ribbonattributes;

}@override

public t call() throws exception

}return target.call();

} finally }}

}

所有步驟完成後再測試灰度發布,發現達到了預期的效果。

前後端分離的問題與解決方案

這些天專案有的api出現版本控制問題,著實忙乎了一小陣,因為專案使用tp5的傳統方法進行版本控制 api目錄下進行版本區分,由請求路徑決定使用的版本 但是問題往往是,專案使用了v2版本,但是後端又新建了v3,而前端不知情,所以也趁著這次機會,探索了較為實用的前後端分離問題與解決方案,並做整理。1.後...

前後端分離與跨域的解決方案

前後端分離與跨域的解決方案 cors的原理 vue中axios傳送options預檢請求的原因及如何通過 ps access control allow origin 該字段是必須的,表示接受任意網域名稱的請求,還可以指定網域名稱。access control allow credentials 該...

檔案(切片)上傳實現解決方案 面試 前後端

思路及原理 1.將大檔案切片 file是blob類的例項,利用其slice方法可以將檔案切片 http可以多個併發傳遞 6 7 2.同時併發n個切片的上傳 3.等n個都上傳完,再傳送請求合併切片 為啥不自動合併呢 3.html 0 server.js new multiparty.form pars...