Categorygithub.com/dipper-iot/dipper-engine
modulepackage
0.0.8-beta3
Repository: https://github.com/dipper-iot/dipper-engine.git
Documentation: pkg.go.dev

# README

Rule Engine Golang

Go CodeQL Coverage Status

Setup

$ go build

Run

$ dipper-engine -h

NAME:
   Dipper Engine - Rule Engine

USAGE:
   Dipper Engine [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --bus value, -b value       Bus type: [chan, redis] (default: "chan")
   --config value, -c value    Config file (default: "config.json")
   --help, -h                  show help (default: false)
   --plugin, -p                Load Plugin (default: false)
   --queue value, -q value     Queue type: [chan, redis] (default: "chan")
   --redis-host value          Redis host (default: "127.0.0.1:6379")
   --redis-pass value          Redis pass
   --redis-timeout value       Redis Time out
   --session-from-queue, --sq  Session from queue (default: false)
   --store value, -s value     Store type: [memory, redis] (default: "memory")


$ dipper-engine

Start Dipper Engine

Rules: 5
-----------------------------------------------------------
No  Rule Name                  Worker  Infinity  Status  
1   arithmetic                 1       false     enable  
2   conditional                1       false     enable  
3   fork                       1       false     enable  
4   input-redis-queue          0       true      disable 
5   input-redis-queue-extend   1       true      enable  
6   log-core                   1       false     enable  
7   output-redis-queue         0       false     disable 
8   output-redis-queue-extend  1       false     enable  
9   switch                     1       false     enable
-----------------------------------------------------------

Running Engine...

Rule Engine

NoRuleDescriptionInfinityDoc
1arithmeticoperator match rulefalse
2conditionalcompare data rulefalse
3forkfork to rulesfalse
4input-redis-queueinput data from queue on configtrue
5input-redis-queue-extendinput data from queue on optiontrue
6log-corelog to consolefalse
7output-redis-queueoutput data from queue on configfalse
8output-redis-queue-extendoutput data from queue on optionfalse
9switchswitch to rulesfalse

Example Developer Test


c := engine.New()

c.Hook(engine.AfterStart, func(dipper *core.DipperEngine, c *cli.Context) error {
    
    factoryResultSessionName := core.FactoryQueueNameDefault[*data.ResultSession]()
    dipper.SessionOutputQueue(factoryResultSessionName)
    
    dipper.OutputSubscribe(context.TODO(), func(sessionDeliver *queue.Deliver[*data.ResultSession]) {
        debug.PrintJson(sessionDeliver.Data, "Result: ")
        sessionDeliver.Ack()
    })
    
    return dipper.Add(context.Background(), &data.Session{
        Data: map[string]interface{}{
            "default": map[string]interface{}{
                "a": 10,
                "b": 20,
                "d": 5,
            },
        },
        ChanId:   "test-1",
        RootNode: "1",
        MapNode: map[string]*data.NodeRule{
            "1": {
                Debug: false,
                Option: map[string]interface{}{
                        "operators": map[string]string{
                        "c": "a+b",
                    },
                    "next_error":   "2",
                    "next_success": "3",
                    "debug":        false,
                },
                NodeId: "4",
                RuleId: "arithmetic",
                End:    false,
            },
            "2": {
                Debug: false,
                Option: map[string]interface{}{
                    "debug": false,
                },
                NodeId: "2",
                RuleId: "log-core",
                End:    true,
            },
            "3": {
                Debug: false,
                Option: map[string]interface{}{
                    "next_success": []string{"5", "2"},
                    "debug":        false,
                },
                NodeId: "3",
                RuleId: "fork",
                End:    false,
            },
            "5": {
                Debug: false,
                Option: map[string]interface{}{
                    "conditional":         "a == b",
                    "set_param_result_to": "cond_a_b",
                    "next_error":          "2",
                    "next_true":           "2",
                    "next_false":          "2",
                    "debug":               false,
                },
                NodeId: "5",
                RuleId: "conditional",
                End:    false,
            },
        },
    })
})

if err := c.Run(os.Args); err != nil {
    log.Fatal(err)
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author