0. Table SQL




/*

RULE ENGINE
     5      : Đã tạo trên process task, chưa đẩy qua queue (Ví dụ process con)
    -5      : là process task SKIP
    -90     : ...

PRODUCER - DELAY - KAFKA
    None = 0,                     // Mới insert vào database, Đẩy vào PRODUCER thành công
    PushKafkaSuccess = 1,         // Push vào kafka success, có dữ liệu PushTime
    PushKafkaFailed = -1,         // Push vào kafka failed
    PushDelaySuccess = 2,         // Push vào service delay success
    PushDelayFailed = -2,         // Push vào service delay failed

CONSUMER
    ConsumerRecived = 3,          // Consumer đã nhận được process
    ProcessDone = 200,            // Process queue thành công
    ProcessFailed = -200,         // Process queue thất bại
    ProcessSkip = 201,            // Process queue đã xử lý và được bỏ qua
   
*/


-- table action - nhóm nhiều task
    SELECT TOP 1000 * FROM SalePlatform..SPF_RuleEngine_Action (NOLOCK)

-- table Task cụ thể
    SELECT TOP 1000 * FROM SalePlatform..SPF_RuleEngine_Task (NOLOCK)

-- table ProcessTask - Task được thực thi và theo dõi
    SELECT TOP 1000 * FROM SalePlatform..SPF_RuleEngine_ProcessTask (NOLOCK)

-- table Queue  
    SELECT TOP 1000 Status,* FROM SalePlatform..SPF_Queue_Transaction (NOLOCK)
    where Status not in ( 200, 201,2000)
    ORDER BY ID DESC

-- table Queue  
    SELECT TOP 2000
             Id,ReferID,ReferType                                       -- ReferID của MBS + và hệ thống khác
            ,RE_ProcessTaskID,RE_PreferID,RE_ReferType,TaskName         -- ProcessTaskID, PreferID, ReferType (RE viết tắt hệ thống RuleEngine)
            ,ConsumerName                                               -- KafkaConsumer1
            ,Delay,CurrentRetry,MaxRetry                                                -- Thời gian chờ      
            ,SchedulerTime,PushTime,RunTime,DoneTime                    -- t/g ước tính đẩy Queue qua Kafka - t/g producer push kafka - t/g consumer call apiimplement - t/g APIImplement chay xong
            ,APICheck,APICheck_Parameter,APICheck_Response              -- API Check
            ,APIImplement,APIImplement_Parameter,APIImplement_Response  -- API sẽ gọi ở consumer để làm nhiệm vụ
            ,Condition_Object, Condition_Type, Condition_Success        -- phương thức call apiimplement khác nhau wcf service hay restapi.
            ,CallBackURL, CallBackURL_Parameter, CallBackURL_Response   -- API gọi về rule engineer, sau khi hoàn tất ở consumer
            ,CreateDate,Status,Note,CreatedDate,UpdatedDate             -- Status : 5,-5 tạo ở rule engine | 0 tạo ở producer | 1,-1 Kafka | 2,-2 Delay |
        FROM SalePlatform..SPF_Queue_Transaction (NOLOCK)



Xem log Queue - Web Admin
   http://saleplatform.fpt.net/web-admin/             (product)
       Login
          Telegram : SalePlatform
           /help
           /token
               isc.vudh



1. Gọi API Push - để tạo process task Rule Engine

url : {{domain}}/rule-engine/api/v1.0/rule-engine/push
input :
{
  "ReferId""1982",
  "ReferType"1,
  "ActionCode""A01",
  "ProcessTaskId"0
}

out :
{
    "Code"200,
    "Message": {
        "Message""Thành công.",
        "ExMessage"null
    },
    "Data"null
}

Gọi API check để biết chạy processtask nào




Xem kibana API push
-- log kibana : http://kibana.isc.net/     -- Topic : dev-mbs-mobisalecore-all     -- source : ... aggregation ...     -- SourceType: USER-LOG

Search thêm rule-engine/push hay "ActionCode", ...





Kiểm tra SQL, table ProcessTask
Thành công process status :
0 : đã đẩy qua queue thành công
5 : Đã tạo trên process task, chưa đẩy qua queue (Ví dụ process con)
-5 : là process task SKIP
-90 : ...
-- table ProcessTask
    select  Id,ReferID,ReferType                                        -- Loại Action
            ,ActionCode,TaskCode,TaskName,ParentTaskCode                -- Thông tin Action , Task
            ,Source,ConsumerName            
            ,Delay,MaxRetry                                             -- Thời gian chờ
            ,APICheck,APICheck_Parameter,APICheck_Response              -- API Check
            ,APIImplement,APIImplement_Method,APIImplement_Header,APIImplement_ContentType,APIImplement_Parameter,APIImplement_Response -- API sẽ gọi ở consumer để làm nhiệm vụ
            ,Condition_Object, Condition_Type, Condition_Success        -- phương thức call apiimplement khác nhau wcf service hay restapi.
            ,CallBackURL, CallBackURL_Parameter, CallBackURL_Response   -- API gọi về rule engineer, sau khi hoàn tất ở consumer 
            ,Status,Note,CreatedDate,UpdatedDate                        -- Status 1 mới tạo
       from SalePlatform..SPF_RuleEngine_ProcessTask PT (nolock)






PRODUCER Insert-queue - RULE-ENGINE GỌI

Kiểm tra SQL, table Queue
-- table Queue_Transaction
    select  Id,ReferID,ReferType                                        -- ReferID của MBS + và hệ thống khác
            ,RE_ProcessTaskID,RE_PreferID,RE_ReferType,TaskName         -- ReferID của riêng MBS
            ,ConsumerName                                               -- KafkaConsumer1
            ,Delay,CurrentRetry,MaxRetry                                                -- Thời gian chờ      
            ,SchedulerTime,PushTime,RunTime,DoneTime                    -- t/g ước tính đẩy Queue qua Kafka - t/g producer push kafka - t/g consumer call apiimplement - t/g APIImplement chay xong
            ,APICheck,APICheck_Parameter,APICheck_Response              -- API Check
            ,APIImplement,APIImplement_Method,APIImplement_Header,APIImplement_ContentType,APIImplement_Parameter,APIImplement_Response -- API sẽ gọi ở consumer để làm nhiệm vụ
            ,Condition_Object, Condition_Type, Condition_Success        -- phương thức call apiimplement khác nhau wcf service hay restapi.
            ,CallBackURL, CallBackURL_Parameter, CallBackURL_Response   -- API gọi về rule engineer, sau khi hoàn tất ở consumer 
            ,CreateDate,Status,Note,CreatedDate,UpdatedDate             -- Status : 5,-5 tạo ở rule engine | 0 tạo ở producer | 1,-1 Kafka | 2,-2 Delay |
     from SalePlatform..SPF_Queue_Transaction QT (nolock)
     order by id desc




url : {{domain}}/producer/api/Producer/insert-queue
input :
{
  "ProcessTaskId"259
  "Delay"0 ,
  "Type"1
}


Xem kibana API insert-queue
-- log kibana : http://kibana.isc.net/     -- Topic : dev-mbs-mobisalecore-all     -- source : ... producer-queue ...     -- SourceType: USER-LOG

Search thêm Producer/insert-queue hay "ProcessTaskId", ...




API api/Producer/insert-queue , RULE-ENGINE gọi, Delay =0 => Đẩy Kafka
API api/Producer/insert-queue , RULE-ENGINE  gọi, Delay >0 => Đẩy Delay


Kiểm tra SQL, table Queue
-- table Queue_Transaction
    select  Id,ReferID,ReferType                                        -- ReferID của MBS + và hệ thống khác
            ,RE_ProcessTaskID,RE_PreferID,RE_ReferType,TaskName         -- ReferID của riêng MBS
            ,ConsumerName                                               -- KafkaConsumer1
            ,Delay,CurrentRetry,MaxRetry                                                -- Thời gian chờ      
            ,SchedulerTime,PushTime,RunTime,DoneTime                    -- t/g ước tính đẩy Queue qua Kafka - t/g producer push kafka - t/g consumer call apiimplement - t/g APIImplement chay xong
            ,APICheck,APICheck_Parameter,APICheck_Response              -- API Check
            ,APIImplement,APIImplement_Method,APIImplement_Header,APIImplement_ContentType,APIImplement_Parameter,APIImplement_Response -- API sẽ gọi ở consumer để làm nhiệm vụ
            ,Condition_Object, Condition_Type, Condition_Success        -- phương thức call apiimplement khác nhau wcf service hay restapi.
            ,CallBackURL, CallBackURL_Parameter, CallBackURL_Response   -- API gọi về rule engineer, sau khi hoàn tất ở consumer 
            ,CreateDate,Status,Note,CreatedDate,UpdatedDate             -- Status : 5,-5 tạo ở rule engine | 0 tạo ở producer | 1,-1 Kafka | 2,-2 Delay |
     from SalePlatform..SPF_Queue_Transaction QT (nolock)
     order by id desc



PRODUCER JOB - Gửi mail




* Job của Producer gửi mail (10 phút gọi 1 lần)
    url   : sale-platform-producer-queue\SchedulerJob\QuartzJob.cs
    title  : Data Mobisale_ProcessQueue bất thường

    -- lấy list queue bất thường => mail
        exec SPF_QUEUE_QueueTransaction_GetList @Type=0

            + Có status = 0,1,3, TimeDelay >= 30 phút, trong ngày
            + Có status = -200 , TimeDelay >= 30 phút, trong ngày, CurrentRetry < MaxRetry

                => C# Producer gửi mail bất thường,
                         ( C# mỗi loại status chỉ lấy top 10 queue đại diện để gửi )




Giả lập dữ liệu SQL , update status , và chờ 10 phút
    update SalePlatform..SPF_Queue_Transaction
            set Status=-200,
                SchedulerTime='2021-10-08 10:24:17.510',
                CurrentRetry=0
        where Id=448

      update SalePlatform..SPF_Queue_Transaction
            set Status=-1,
                SchedulerTime='2021-10-08 10:24:17.510',
                CurrentRetry=0
        where Id=449



Xem kibana API ProducerJob
ko ghi log



Xem Email gửi
title  : Data Mobisale_ProcessQueue bất thường
                    Queue - [STAG]





PRODUCER JOB - Gửi auto cập nhật status 2,-2 và bắn Kafka


* Job của Producer bắn Kaffka (10 phút gọi 1 lần)        
    --lấy list queue -2,2 => kaffka
        exec SPF_QUEUE_QueueTransaction_GetList @Type=1

         + Có Status = -2  và TimeDelay >=   0 phút 
         + Có Status = 2 và TimeDelay >= 30 phút           

          => đẩy Kaffka



Giả lập dữ liệu SQL , update status , và chờ 10 phút
    update SalePlatform..SPF_Queue_Transaction
            set Status=-2,
                SchedulerTime='2021-10-08 10:24:17.510',
                CurrentRetry=0
        where Id=448

      update SalePlatform..SPF_Queue_Transaction
            set Status=2,
                SchedulerTime='2021-10-08 10:24:17.510',
                CurrentRetry=0
        where Id=449




Kiểm tra SQL, table Queue
-- table Queue_Transaction
    select  Id,ReferID,ReferType                                        -- ReferID của MBS + và hệ thống khác
            ,RE_ProcessTaskID,RE_PreferID,RE_ReferType,TaskName         -- ReferID của riêng MBS
            ,ConsumerName                                               -- KafkaConsumer1
            ,Delay,CurrentRetry,MaxRetry                                                -- Thời gian chờ      
            ,SchedulerTime,PushTime,RunTime,DoneTime                    -- t/g ước tính đẩy Queue qua Kafka - t/g producer push kafka - t/g consumer call apiimplement - t/g APIImplement chay xong
            ,APICheck,APICheck_Parameter,APICheck_Response              -- API Check
            ,APIImplement,APIImplement_Method,APIImplement_Header,APIImplement_ContentType,APIImplement_Parameter,APIImplement_Response -- API sẽ gọi ở consumer để làm nhiệm vụ
            ,Condition_Object, Condition_Type, Condition_Success        -- phương thức call apiimplement khác nhau wcf service hay restapi.
            ,CallBackURL, CallBackURL_Parameter, CallBackURL_Response   -- API gọi về rule engineer, sau khi hoàn tất ở consumer 
            ,CreateDate,Status,Note,CreatedDate,UpdatedDate             -- Status : 5,-5 tạo ở rule engine | 0 tạo ở producer | 1,-1 Kafka | 2,-2 Delay |
     from SalePlatform..SPF_Queue_Transaction QT (nolock)
     order by id desc





Xem kibana API insert-queue
-- log kibana : http://kibana.isc.net/     -- Topic : dev-mbs-mobisalecore-all     -- source : ... producer-queue ...     -- SourceType: USER-LOG

Search thêm Producer/insert-queue hay "queue_pushkafka", ...





Delay - API insert-queue lưu vào redis


API insert-queue
url : {{domain}}/delay/api/Delay/insert-queue
input : {"IdQueue":450,"TimestampDelay":"1633679778"}

+ Nếu schetime đã hết hạn bắn lại cho producer
+ Nếu schetime chưa đến hạn
- Kếu key chưa có trong redis   : lưu vào redis
- Nếu key đã có                 : báo lỗi và không lưu vào redis nữa




Xem kibana API insert-queue
-- log kibana : http://kibana.isc.net/     -- Topic : dev-mbs-mobisalecore-all   
Search thêm "InsertQueue", ...