新来个技术总监,使用流程引擎优化复杂的业务代码,老板惊呆了!
mall瀛︿範鏁欑▼瀹樼綉锛歮acrozheng.com
鎺ュ埌闇姹
鏈杩戞濂藉叕鍙搁噷鏈変釜闇姹傦紝涓涓煭淇′笟鍔℃帴浜嗗涓涓夋柟渚涘簲鍟嗭紝鏌愪簺涓氬姟闇瑕佹煡璇㈢涓夋柟渚涘簲鍟嗗墿浣欑殑鐭俊鍖呮暟閲忓幓閫夋嫨鍓╀綑閲忔渶澶氱殑娓犻亾鍘绘壒閲忓彂閫併傛湁浜涗笟鍔℃槸鎸囧畾浜嗘煇涓煭淇′緵搴斿晢锛屾湁浜涘満鏅渶瑕佹牴鎹笟鍔$殑鍊煎幓鍔ㄦ佸垽鏂鐢ㄥ摢涓緵搴斿晢銆傚満鏅潪甯稿鏉傦紝杩樼粡甯稿彉鍖栥
浠ュ墠鐨勪唬鐮佸疄鍦ㄦ儴涓嶅繊鐫癸紝閫夋嫨鍓╀綑閲忔渶澶氱殑娓犻亾鏄竴涓釜鍘绘煡鐨勶紝鐒跺悗鑾峰緱缁撴灉鍘绘瘮杈冦傝嚦浜庢寚瀹氱殑渚涘簲鍟嗗拰鏍规嵁涓氬姟鐨勫煎幓鍒ゆ柇閫夋嫨渚涘簲鍟嗗垯鏄敤澶ч噺鐨刬f else鍘诲祵濂楀悇绉嶅垽鏂傛瘡娆$湅鍒拌繖鍧ㄤ唬鐮佺湡鐨勮寰楀お绮楃硻浜嗐傚叧閿槸鏈変簺渚涘簲鍟嗚繕缁忓父鍙橈紝鏂版帴鐨勪緵搴斿晢闇瑕佹浛浠f棫鐨勪緵搴斿晢锛屽姞鍏ヨ繖涓澶у潹浠g爜閲屻備笟鍔$殑鍒ゆ柇鏉′欢杩樻椂涓嶆椂鍙樺寲涓涓嬨
鍑轰簡鍑犳闂涔嬪悗锛岄瀵肩湅涓嶄笅鍘讳簡锛屽彨鎴戞兂鍔炴硶鍘讳紭鍖栥
鎴戠悊浜嗙悊閫昏緫锛屾暣涓叧绯诲浘搴旇鏄繖鏍风殑锛屽叾涓垜鎶婁竴涓釜鍘绘煡鐨勫彉鎴愪簡骞惰鍘绘煡锛屼负浜嗚妭绾︿覆琛屽幓鏌ョ殑IO鑰楁椂闂銆
鍏朵腑鏈変簺澶嶆潅鏌ュ簱閫昏緫锛屽垽鏂箓绛夋х殑姝ラ鎴戝氨鍘绘帀浜嗐傚彧鎸戦変簡鍏抽敭鐨勬楠ょ敾涓婂幓銆
鍙垜鍘婚噸鏋勮繖涓參鎱㈠啓涔熻兘鍐欏嚭锛屼絾鏄叧閿殑鏄紝姣忎釜姝ラ鍜屽垽鏂昏緫杩樻椂涓嶆椂鍙樺寲涓嬨傝繖灏辫姹傛垜鐨勪唬鐮侀潪甯哥伒娲汇傛墍浠ュ湪璁捐鏃讹紝涓鐩村緢鑻︽伡璇ュ浣曞幓璁捐銆
閫夋嫨瑙勫垯寮曟搸
鍦ㄥ皬缁勫紑浜ゆ祦浼氱殑鏃跺欙紝鏈夊叾浠栫粍鐨勫皬浼欎即鍜屾垜瀹夊埄浜嗕竴涓紑婧愭鏋-LiteFlow銆
缁忚繃鐮旂┒杩欐寮婧愭鏋讹紝鍙戠幇LiteFlow鏄竴涓浗浜ц鍒欏紩鎿庯紝鑳藉缂栨帓浠绘剰澶嶆潅鐨勬祦绋嬶紝杩樻敮鎸佺儹鍒锋柊銆傝繖鍩烘湰涓婂畬鍏ㄥ鍚堟垜鐨勯渶姹傚晩锛
鏂囨。寰堣缁嗭紝寰圢ICE锛屽ぇ姒傜湅浜嗗崐澶╁氨鍏ㄩ儴瀛﹀畬浜嗐傚彂鐜版柊鐗堟湰鐨凩iteFlow鐨勮鍒欐槸鐢‥L琛ㄨ揪寮忔潵鍐欑殑銆傝娉曟诲叡鏁颁笅鏉ヤ篃灏10涓乏鍙筹紝闈炲父濂界悊瑙c
姣斿杩欑鍥撅細
杩欐垨璁告槸涓涓浣犳湁鐢ㄧ殑寮婧愰」鐩紝mall椤圭洰鏄竴濂楀熀浜 SpringBoot + Vue + uni-app 瀹炵幇鐨勭數鍟嗙郴缁燂紙Github鏍囨槦60K锛夛紝閲囩敤Docker瀹瑰櫒鍖栭儴缃诧紝鍚庣鏀寔澶氭ā鍧楀拰寰湇鍔℃灦鏋勩傚寘鎷墠鍙板晢鍩庨」鐩拰鍚庡彴绠$悊绯荤粺锛岃兘鏀寔瀹屾暣鐨勮鍗曟祦绋嬶紒娑电洊鍟嗗搧銆佽鍗曘佽喘鐗╄溅銆佹潈闄愩佷紭鎯犲埜銆佷細鍛樸佹敮浠樼瓑鍔熻兘锛
- Boot椤圭洰锛歨ttps://github.com/macrozheng/mall
- Cloud椤圭洰锛歨ttps://github.com/macrozheng/mall-swarm
- 瑙嗛鏁欑▼锛歨ttps://www.macrozheng.com/video/
椤圭洰婕旂ず锛
鍦↙iteFlow鐢ㄨ鍒欒〃绀哄氨鏄細
<chain name="chain1">
THEN(
a,
WHEN(b, THEN(c, d)),
e
)
</chain>
鍏朵腑THEN鏄唬琛ㄤ覆琛岋紝WHEN浠h〃骞惰鎵ц锛岃繖绉嶈娉曪紝涓鐪嬪氨寰堝ソ鐞嗚В銆
鍐嶆潵鐪嬭繖涓浘锛
鍦↙iteFlow閲岃鍒欒〃绀哄氨鏄細
<chain name="chain1">
THEN(
a,
WHEN(
b,
SWITCH(c).to(d,e)
),
f
)
</chain>
鍏朵腑SWITCH鍏抽敭瀛楀氨鏄帓浠栫綉鍏崇殑鎰忔濓紝c杩欎釜缁勪欢鏄竴涓猨ava绫伙紝鏍规嵁鎵ц鐨勭粨鏋滃幓閫夋嫨鍒板簳搴旇鎵цd杩樻槸e銆
鎵浠ヨ繖鏍峰祵濂楀灞備篃搴旇鏄鏃犻棶棰樼殑銆
LiteFlow鐨勬枃妗i噷浣滆呯粰鍑轰簡寰堣缁嗙殑渚嬪瓙锛岃繕鏈変竴浜涘鏉備緥瀛愶紝姣斿锛
杩欑澶嶆潅鐨勪緥瀛愮敤LiteFlow鐨勮〃杈惧紡鍙互鍐欐垚锛
<chain name="chain1">
THEN(
A,
WHEN(
THEN(B, C),
THEN(D, E, F),
THEN(
SWITCH(G).to(
THEN(H, I, WHEN(J, K)).id("t1"),
THEN(L, M).id("t2")
),
N
)
),
Z
)
</chain>
瀹冪殑琛ㄨ揪寮忚繕鍙互杩涜瀹氫箟瀛愬彉閲忥紝涓婅堪琛ㄨ揪寮忓張鍙互鍐欐垚锛
<chain name="chain1">
item1 = THEN(B, C);
item2 = THEN(D, E, F);
item3_1 = THEN(H, I, WHEN(J, K)).id("t1");
item3_2 = THEN(L, M).id("t2");
item3 = THEN(SWITCH(G).to(item3_1, item3_2), N);
THEN(
A,
WHEN(item1, item2, item3),
Z
);
</chain>
鍏跺疄瀵圭収鍥撅紝浠旂粏鐪嬶紝浼氳寰楄繖绉嶈〃杈惧紡杩樻槸寰堟竻鏅扮殑銆傝繍鐢ㄥ埌鎴戦偅涓煭淇$郴缁熼噷鏄话缁版湁浣欑殑銆
娴佺▼鐨勮〃杈惧紡
鎴戠爺绌朵簡涓嬶紝鑺变簡10鍒嗛挓鏃堕棿锛屽氨鍐欏嚭浜嗘垜閭d釜娴佺▼鐨勮〃杈惧紡瑙勫垯锛
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="channelSenderChain">
selectBestChannel = THEN(
WHEN(
channel1Query, channel2Query, channel3Query,
channel4Query, channel5Query, channel6Query
),
channelSelector
).id("branch1");
selectBizChannel = THEN(
biz1,
SWITCH(if_2).to(
channel3,
channel4,
SWITCH(if_3).to(channel5, channel6).id("s3")
).id("s2")
).id("branch2");
THEN(
packageData,
SWITCH(if_1).to(
channel1,
channel2,
selectBestChannel,
selectBizChannel
),
batchSender
);
</chain>
</flow>
鎴戠敤浜嗘枃妗d腑鎻愬埌鐨勫瓙鍙橀噺鐨勬柟寮忓幓鍐欙紝杩欑鍐欐硶鏇村姞娓呮櫚銆傚叾瀹炴垜鎬荤粨浜嗕竴涓皬绐嶉棬灏辨槸锛**鍐嶅鏉傜殑鍥撅紝閮藉彲浠ユ媶鍒嗘垚涓涓釜灞閮ㄧ殑鏁翠綋锛屽厛瀹氬眬閮ㄧ殑灏忓彉閲忥紝鐒跺悗鍦ㄤ富瑕佺殑娴佺▼閲屽幓寮曞叆杩欎簺灞閮ㄥ彉閲忓氨鍙互浜嗐**鍙嶆鎴戝啓杩欎釜鍥剧殑娴佺▼灏卞樊涓嶅10鍒嗛挓銆
鑷充簬涓涓釜灏忕粍浠躲傛垜灏辫窡鐫鏂囨。閲屽仛浜嗕竴閬嶏紝鎶婂師鏉ョ殑澶ч昏緫鏀规媶鎴愪竴涓釜鐨勫皬閫昏緫銆傚皝瑁呭湪涓嶅悓鐨勭粍浠堕噷锛岀粰涓婄浉搴旂殑Id灏卞彲浠ヤ簡銆
鏈鍚庨氳繃LiteflowExecutor瑙﹀彂涓嬪氨鍙互浜嗐
LiteflowResponse response = flowExecutor.execute2Resp("channelSenderChain", null, BatchMessageResultContext.class);
BatchMessageResultContext context = response.getFirstContextBean();
if (response.isSuccess()){
log.info("鎵ц鎴愬姛锛屾渶缁堥夋嫨鐨勬笭閬撴槸{}", context.getFinalResultChannel());
}else{
log.error("鎵ц澶辫触", response.getCause());
}
闈炲父绠鍗曟湁鏈ㄦ湁锛侊紒锛
鑰屼笖鐗瑰埆浼橀泤锛侊紒锛
瀹屽叏瑙h︿簡
鎴戞敼鎴愪笂闈㈣繖绉嶅舰寮忎簡涔嬪悗锛屾瘡涓涓皬閫昏緫鍧椾箣闂村氨瀹屽叏瑙h︿簡銆傚綋涓暟鎹殑杩炴帴瀹屽叏鏄潬
涓婁笅鏂
杩涜杩炴帴鐨勶紝鍦ㄧ爺绌朵簡LiteFlow鐨勭悊蹇典箣鍚庯紝鎴戝彂鐜拌繖鐞嗗康鐗瑰埆濂姐傜洿鎺ユ妸鍘熷厛鐨勮﹀悎鎬х壒鍒己鐨勪唬鐮佺粰鎷嗗垎寮鏉ヤ簡銆鐜板湪涓氬姟鏈夊彉鍔ㄧ殑璇濓紝鎴戝彧闇瑕佹敼鍐欏叾涓竴涓粍浠跺氨鍙互浜嗐傝屼笖缁勪欢鏄彲浠ユ嬁鏉ュ鐢ㄧ殑銆備箣闂寸殑椤哄簭涔熸槸鍙互闅忔剰鍒囨崲鐨勩傝繖涓鍒囷紝鍙渶瑕佹敼瑙勫垯鏂囦欢鍗冲彲銆備唬鐮佹槸瀹屽叏涓嶇敤鍔ㄧ殑銆
鎴戜粩缁嗙炕鐪嬩簡鏂囨。锛岃繖妗嗘灦杩樻敮鎸佸畬鍏ㄦ棤缂濈殑鐑埛鏂帮紝铏界劧鎴戠殑浠g爜娌$敤鍒拌繖鐗癸紝浣嗘槸鐪嬭捣鏉ョ湡鐨勬槸澶帀瀹充簡锛屾敼鍙樿鍒欑殑缂栨帓杩為噸鍚簲鐢ㄩ兘涓嶉渶瑕侊紒锛侊紒涓嶈繃鎴戞墦姝婚兘涓嶄細鐢ㄨ繖涓壒鎬х殑锛岄瀵煎彨鎴戞敼涓氬姟锛屾垜杩樻兂澶氭姤鐐瑰伐鏃讹紝杩欎釜濡傛灉涓婄嚎浜嗭紝鎴戝氨娌℃硶澶氭姤宸ユ椂浜嗐傘傘傪煠
LiteFlow杩樻湁寰堝楂樼骇鐗规э紝姣斿闅愬紡娴佺▼鍟婏紝浜嬩欢鍥炶皟鍟婏紝澹版槑寮忕粍浠讹紝缁勪欢鍒囬潰鍟婏紝姝ラ淇℃伅锛岀嚎绋嬫睜鐨勮嚜瀹氫箟锛岀鏈夋姇閫掞紝杩樻湁绠鍗曠洃鎺с傝繖娆惧浗浜ц鍒欏紩鎿庡揩瑕佺帺鍑鸿姳浜嗭紝寮哄ぇ锛
閲嶇偣瑕佽涓婰iteFlow鐨勮剼鏈粍浠惰繖涓姛鑳 锛岃繖涓姛鑳芥槸鎴戝啓濂戒唬鐮佹墠鍙戠幇鐨勩傛垜鍙戠幇锛屽鏋滅敤鑴氭湰缁勪欢鐨勮瘽浼氭洿鐏垫椿銆
铏界劧LiteFlow鏀寔鐑埛鏂帮紝浣嗕篃浠呴檺浜庤鍒欐枃浠舵敼鍙樸備綘Java浠g爜鏀瑰彉锛岃繕寰楅噸鍚
浣嗘槸LiteFlow鐨勮剼鏈粍浠惰繛杩欏眰閮界粰浣犳崊鐮翠簡锛屼綘鍙互瀹氫箟鑴氭湰锛岃繕鏀寔groovy鑴氭湰锛岃繖涓嬶紝杩炴敼鍙橀昏緫閮戒笉鐢ㄩ噸鍚簲鐢ㄤ簡銆傘
浠嬩簬鎴戜笂闈㈢殑绉佸績锛屾垜鍚屾牱涔熶笉浼氭妸杩欏姛鑳藉憡璇夐瀵拣煒呫
鍙帺鐐归潪甯稿
鎴戦噸鏋勫畬杩欎釜椤圭洰涔嬪悗锛屽彂鐜癓iteFlow杩欎釜妗嗘灦鐨勫彲鐜╃偣闈炲父澶氥
铏界劧瀹樻柟鏄绉版槸瑙勫垯寮曟搸锛岄傜敤浜庣敤鏉ヨВ鑰︾郴缁燂紝缁勪欢缂栨帓銆備絾鏄垜鍙戠幇鐢ㄥ畠鏉ュ仛涓浜涚畝鍗曠殑寮傛绾跨▼缂栨帓涔熸槸闈炲父nice鐨勩傛垜鑷繁鏈韩瀵瑰绾跨▼涓嶅お绮鹃氾紝鐢ㄨ繖涓潵鍐欙紝澶柟渚夸簡銆
LiteFlow闄や簡瑙勫垯鏂囦欢涔嬪锛岃繕鏀寔浠g爜褰㈠紡鐨勯摼寮忕粍瑁呰鍒欙紝杩欎釜鐗规ф濂界敤鏉ュ啓澶氱嚎绋嬨
姣斿锛屾垜瑕佸啓涓涓繖鏍风殑澶氱嚎绋嬩緥瀛愶細
瑕佽鎴戠敤CompletableFuture鏉ュ啓锛屾垜杩樼湡涓嶅お浼氥備絾鏄綘鐢↙iteFlow灏卞緢瀹规槗锛屽湪LiteFlow浣犳棤闇瀹氫箟绾跨▼锛屾鏋惰嚜宸变細涓轰綘鍒涘缓绾跨▼锛屼綘鍙渶瑕佹妸浣犵嚎绋嬮噷鐨勪唬鐮佸彉鎴愪竴涓釜缁勪欢锛岀劧鍚庣敤浠g爜瀹氫箟瑙勫垯灏卞彲浠ヤ簡銆
鍐欐硶濡備笅锛
String el = "THEN(" +
" main1," +
" WHEN(" +
" THEN(c1, c2, WHEN(c3, c4))," +
" THEN(c5, c6)" +
" )," +
" main2" +
" )";
LiteFlowChainELBuilder.createChain().setChainName("testChain").setEL(el).build();
LiteflowResponse response = flowExecutor.execute2Resp("testChain", 娴佺▼鍒濆鍙傛暟, 浣犵殑涓婁笅鏂.class);
灏辫繖鏍峰嵆瀹屾垚浜嗚繖涓湅涓婂幓鏈夌偣澶嶆潅鐨勭嚎绋嬬紪鎺掍簡銆傝繖娆炬鏋剁畝鐩存槸瀵逛笉浼氬啓澶氱嚎绋嬪皬鐧界殑绂忛煶鍟娿傜埍浜嗙埍浜嗐
鎬荤粨
椤轰究杩樿璇翠笅鐨勬槸锛屽畼缃戠殑鏂囩珷瓒呰缁嗐傜ぞ鍖虹兢涔熷緢娲昏穬銆
浠ヤ笅鏄疞iteFlow鐨凣itee鐨勪粨搴撳湴鍧锛屽ぇ瀹跺彲浠ュ叧娉ㄤ笅杩欐鍥戒骇瑙勫垯寮曟搸
https://gitee.com/dromara/liteFlow
涓轰簡鏂逛究鐞嗚В锛屾垜鐗瑰湴鎶婃垜閭d釜鐭俊鐨勪緥瀛愯繘琛屼簡mock鍚庢帹鍒颁簡github浠撳簱锛屽ぇ瀹跺彲浠ヨ嚜琛宲ull涓嬫潵鐜╄嶃
https://github.com/bryan31/message-demo
Github涓
鏍囨槦60K
鐨勭數鍟嗗疄鎴橀」鐩甿all锛屽叏濂 瑙嗛鏁欑▼锛2023鏈鏂扮増锛 宸叉洿鏂板畬姣曪紒鍏ㄥ鏁欑▼绾40灏忔椂锛屽叡113鏈
锛岄氳繃杩欏鏁欑▼浣犲彲浠ユ嫢鏈変竴涓娑电洊涓绘祦Java鎶鏈爤鐨勫畬鏁撮」鐩粡楠
锛屽悓鏃舵彁楂樿嚜宸鐙珛寮鍙戜竴涓」鐩殑鑳藉姏
锛屼笅闈㈡槸椤圭洰鐨勬暣浣撴灦鏋勫浘锛屾劅鍏磋叮鐨勫皬浼欎即鍙互鐐瑰嚮閾炬帴 mall瑙嗛鏁欑▼ 鍔犲叆瀛︿範銆鏁村 瑙嗛鏁欑▼ 鐨勫唴瀹硅繕鏄潪甯稿畬鍠勭殑锛屾兜鐩栦簡mall椤圭洰鏈浣冲涔犺矾绾裤佹暣浣撴鏋舵惌寤恒佷笟鍔′笌鎶鏈疄鐜板叏鏂逛綅瑙f瀽銆佺嚎涓奃ocker鐜閮ㄧ讲銆佸井鏈嶅姟椤圭洰瀛︿範绛夊唴瀹癸紝鍏蜂綋澶х翰鍙互鍙傝冧笅鍥撅紝浣犱篃鍙互鐐瑰嚮閾炬帴 mall瑙嗛鏁欑▼ 浜嗚В鏇村鍐呭銆
鎺ㄨ崘闃呰
- 69K Star锛佽繖鏄垜瑙佽繃鏈寮虹殑寮婧愮數鍟嗙郴缁 锛侊紒
- Github鏍囨槦60K锛佷竴濂楀畬鏁寸殑椤圭洰瀹炴垬鏁欑▼鏉ヤ簡锛屼富娴丣ava鎶鏈竴缃戞墦灏斤紒
- 鐪嬩簡鎴戦」鐩腑璐墿杞︺佽鍗曘佹敮浠樹竴鏁村璁捐锛屽悓浜嬩篃寮濮嬫倓鎮勬ā浠夸簡...
- 璁㈠崟绯荤粺灏辫杩欎箞璁捐锛岀ǔ鐨勪竴鎵癸紒
- 鏀粯绯荤粺灏辫杩欎箞璁捐锛岀ǔ鐨勪竴鎵癸紒
- 鏉冮檺绯荤粺灏辫杩欎箞璁捐锛岀ǔ鐨勪竴鎵癸紒