食堂刷卡機(jī)請求超時(shí)
網(wǎng)上關(guān)于食堂刷卡機(jī)請求超時(shí),利用blink CEP實(shí)現(xiàn)流計(jì)算中的超時(shí)統(tǒng)計(jì)問題的刷卡知識(shí)比較多,也有關(guān)于食堂刷卡機(jī)請求超時(shí)的問題,今天第一pos網(wǎng)(m.fzog.com.cn)為大家整理刷卡常見知識(shí),未來的我們終成一代卡神。
本文目錄一覽:
食堂刷卡機(jī)請求超時(shí)
案例與解決方案匯總頁:
阿里云實(shí)時(shí)計(jì)算產(chǎn)品案例&解決方案匯總
https://yq.aliyun.com/articles/691499
一. 背景介紹如<利用blink+MQ實(shí)現(xiàn)流計(jì)算中的延時(shí)統(tǒng)計(jì)問題>一文中所描述的場景,我們將其簡化為以下案例:
實(shí)時(shí)流的數(shù)據(jù)源結(jié)構(gòu)如下:
我們期望通過以上數(shù)據(jù)源,按照支付日期統(tǒng)計(jì),每個(gè)倉庫的倉接單量、倉出庫量、倉接單超2H未出庫單量、倉接單超6H未出庫單量??梢钥闯觯渲蠰P1倉接單時(shí)間是2018-08-01 09:00,但一直到2018-08-01 12:00點(diǎn)之前,一直都沒有出庫,LP1滿足倉接單超2H未出庫的行為。
該場景的難點(diǎn)就在于:訂單未出庫。而對于TT中的源消息流,訂單未出庫,TT就不會(huì)下發(fā)新的消息,不下發(fā)新的消息,blink就無法被觸發(fā)計(jì)算。而針對上述的場景,對于LP1,我們需要在倉接單時(shí)間是2018-08-01 09:00+2H,也就是2018-08-01 11:00的之后,就要知道LP1已經(jīng)倉接單但超2H未出庫了。
二. 解決方案本文主要是利用blink CEP來實(shí)現(xiàn)上述場景,具體實(shí)現(xiàn)步驟如下所述。
第一步:在source DDL中定義event_timestamp,并定義sink,如下:
----定義sourcecreate table sourcett_dwd_ri( lg_order_code varchar comment \'物流訂單號(hào)\' ,ded_pay_time varchar comment \'支付時(shí)間\' ,store_code varchar comment \'倉庫編碼\' ,store_name varchar comment \'倉庫名稱\' ,wms_create_time varchar comment \'倉接單時(shí)間\' ,wms_consign_create_time varchar comment \'倉出庫時(shí)間\' ,evtstamp as case when coalesce(wms_create_time, \'\') <> \'\' then to_timestamp(wms_create_time, \'yyyy-MM-dd HH:mm:ss\') else to_timestamp(\'1970-01-01 00:00:00\', \'yyyy-MM-dd HH:mm:ss\') end --構(gòu)造event_timestamp,如果源表本身帶有消息的occur_time,可直接選擇occur_time作為event_timestamp ,WATERMARK FOR evtstamp AS withOffset(evtstamp, 10000) --設(shè)置延遲10秒處理)with( type=\'tt\' ,topic=\'dwd_ri\' ,accessKey=\'xxxxxx\' ,accessId=\'xxxxxx\' ,lengthCheck=\'PAD\' ,nullValues=\'\\\\N|\');----定義sinkcreate table sink_hybrid_blink_cep( ded_pay_date varchar comment \'支付日期\' ,store_code varchar comment \'倉庫編碼\' ,store_name varchar comment \'倉庫名稱\' ,wms_create_ord_cnt bigint comment \'倉接單量\' ,wms_confirm_ord_cnt bigint comment \'倉出庫量\' ,wmsin_nowmsout_2h_ord_cnt bigint comment \'倉接單超2小時(shí)未出庫單量\' ,wmsin_nowmsout_6h_ord_cnt bigint comment \'倉接單超6小時(shí)未出庫單量\' ,sub_partition bigint comment \'二級分區(qū)(支付日期)\' ,PRIMARY KEY (ded_pay_date, store_code, sub_partition))with( type=\'PetaData\' ,url = \'xxxxxx\' ,tableName=\'blink_cep\' ,userName=\'xxxxxx\' ,password=\'xxxxxx\' ,bufferSize=\'30000\' ,batchSize=\'3000\' ,batchWriteTimeoutMs=\'15000\');
第二步:根據(jù)blink CEP的標(biāo)準(zhǔn)語義進(jìn)行改寫,如下:
create view blink_cep_v1asselect \'倉接單-倉出庫超時(shí)\' as timeout_type ,lg_order_code ,wms_create_time as start_time ,wms_consign_create_time as end_timefrom source_dwd_csn_whc_lgt_fl_ord_riMATCH_RECOGNIZE( PARTITION BY lg_order_code ORDER BY evtstamp MEASURES e1.wms_create_time as wms_create_time ,e2.wms_consign_create_time as wms_consign_create_time ONE ROW PER MATCH WITH TIMEOUT ROWS --重要,必須設(shè)置延遲也下發(fā) AFTER MATCH SKIP TO NEXT ROW PATTERN (e1 -> e2) WITHIN INTERVAL \'6\' HOUR EMIT TIMEOUT (INTERVAL \'2\' HOUR, INTERVAL \'6\' HOUR) DEFINE e1 as e1.wms_create_time is not null and e1.wms_consign_create_time is null ,e2 as e2.wms_create_time is not null and e2.wms_consign_create_time is not null)where wms_create_time is not null --重要,可以大大減少進(jìn)入CEP的消息量and wms_consign_create_time is null --重要,可以大大減少進(jìn)入CEP的消息量;
第三步:根據(jù)blink的執(zhí)行機(jī)制,我們通過源實(shí)時(shí)流sourcett_dwd_ri與超時(shí)消息流blink_cep_v1關(guān)聯(lián),來觸發(fā)blink對超時(shí)消息進(jìn)行聚合操作,如下:
create view blink_cep_v2asselect a.lg_order_code as lg_order_code ,last_value(a.store_code ) as store_code ,last_value(a.store_name ) as store_name ,last_value(a.ded_pay_time ) as ded_pay_time ,last_value(a.wms_create_time ) as wms_create_time ,last_value(a.real_wms_confirm_time ) as real_wms_confirm_time ,last_value(case when coalesce(a.wms_create_time, \'\') <> \'\' and coalesce(a.real_wms_confirm_time, \'\') = \'\' and now() - unix_timestamp(a.wms_create_time,\'yyyy-MM-dd HH:mm:ss\') >= 7200 then \'Y\' else \'N\' end) as flag_01 ,last_value(case when coalesce(a.wms_create_time, \'\') <> \'\' and coalesce(a.real_wms_confirm_time, \'\') = \'\' and now() - unix_timestamp(a.wms_create_time,\'yyyy-MM-dd HH:mm:ss\') >= 21600 then \'Y\' else \'N\' end) as flag_02from (select lg_order_code as lg_order_code ,last_value(store_code ) as store_code ,last_value(store_name ) as store_name ,last_value(ded_pay_time ) as ded_pay_time ,last_value(wms_create_time ) as wms_create_time ,last_value(wms_consign_create_time) as real_wms_confirm_time from sourcett_dwd_ri group by lg_order_code ) aleft outer join (select lg_order_code ,count(*) as cnt from blink_cep_v1 group by lg_order_code ) bon a.lg_order_code = b.lg_order_codegroup by a.lg_order_code;insert into sink_hybrid_blink_cepselect regexp_replace(substring(a.ded_pay_time, 1, 10), \'-\', \'\') as ded_pay_date ,a.store_code ,max(a.store_name) as store_name ,count(case when coalesce(a.wms_create_time, \'\') <> \'\' then a.lg_order_code end) as wmsin_ord_cnt ,count(case when coalesce(a.real_wms_confirm_time, \'\') <> \'\' then a.lg_order_code end) as wmsout_ord_cnt ,count(case when a.flag_01 = \'Y\' then a.lg_order_code end) as wmsin_nowmsout_2h_ord_cnt ,count(case when a.flag_02 = \'Y\' then a.lg_order_code end) as wmsin_nowmsout_6h_ord_cnt ,cast(regexp_replace(SUBSTRING(ded_pay_time, 1, 10), \'-\', \'\') as bigint) as sub_partitionfrom blink_cep_v2 as t1where coalesce(lg_cancel_time, \'\') = \'\'and coalesce(ded_pay_time, \'\') <> \'\'group by regexp_replace(substring(ded_pay_time, 1, 10), \'-\', \'\') ,a.store_code;三. 問題拓展blink CEP的參數(shù)比較多,要完全看懂,著實(shí)需要一些時(shí)間,但CEP的強(qiáng)大是毋庸置疑的。CEP不僅可以解決物流場景中的超時(shí)統(tǒng)計(jì)問題,風(fēng)控中的很多場景也是信手拈來。這里有一個(gè)風(fēng)控中的場景,通過上述物流案例的用法,我們是否能推敲出這個(gè)場景的用法呢?風(fēng)控案例測試數(shù)據(jù)如下:
我們認(rèn)為,當(dāng)一張銀行卡在10min之內(nèi),在不同的地點(diǎn)被刷卡大于等于兩次,我們就期望對消費(fèi)者出發(fā)預(yù)警機(jī)制。
blink CEP是萬能的么?答案是否定的,當(dāng)消息亂序程度比較高的時(shí)候,實(shí)時(shí)性和準(zhǔn)確性就成了一對矛盾的存在。要想實(shí)時(shí)性比較高,必然要求設(shè)置的offset越小越好,但offset設(shè)置比較小,就直接可能導(dǎo)致很多eventtime<watermark-offset的消息,直接被丟棄,準(zhǔn)確性很難保證。比如,在CP回傳物流詳情的時(shí)候,經(jīng)?;貍鞯臅r(shí)間跟實(shí)操的時(shí)間差異很大(實(shí)操時(shí)間是10點(diǎn),但回傳時(shí)間是15點(diǎn)),如果以實(shí)操時(shí)間作為eventtime,可能就會(huì)導(dǎo)致這種差異很大的消息被直接丟掉,無法進(jìn)入CEP,進(jìn)而無法觸發(fā)CEP后續(xù)的計(jì)算,在使用CEP的過程中,應(yīng)該注意這一點(diǎn)。四. 作者簡介花名:緣橋,來自菜鳥-CTO-數(shù)據(jù)部-倉配數(shù)據(jù)研發(fā),主要負(fù)責(zé)菜鳥倉配業(yè)務(wù)的離線和實(shí)時(shí)數(shù)據(jù)倉庫建設(shè)以及創(chuàng)新數(shù)據(jù)技術(shù)和工具的探索和應(yīng)用。
以上就是關(guān)于食堂刷卡機(jī)請求超時(shí),利用blink CEP實(shí)現(xiàn)流計(jì)算中的超時(shí)統(tǒng)計(jì)問題的知識(shí),后面我們會(huì)繼續(xù)為大家整理關(guān)于食堂刷卡機(jī)請求超時(shí)的知識(shí),希望能夠幫助到大家!
轉(zhuǎn)載請帶上網(wǎng)址:http://m.fzog.com.cn/shuaka/53388.html
- 上一篇:藥店刷卡機(jī)簽到流程
- 下一篇:用poss刷卡機(jī)注冊了怎么注銷