Logstash顺序线程执行流程

时间:2016-08-04 14:10:32

标签: logstash logstash-input-jdbc

我在配置中创建了两个jdbc部分,但我希望始终执行第一个actionA而不是actionB,这对我很重要。我怎样才能做到这一点?

这是我的配置:

input {
    jdbc {
        type => "actionA"
        jdbc_validate_connection => true
        jdbc_connection_string => "jdbc:oracle:thin:@mycomp:1522/db1"
        ...
        statement => "SELECT ID FROM my_table WHERE delete='Y'"
       }

    jdbc {
        type => "actionB"
        jdbc_validate_connection => true
        jdbc_connection_string => "jdbc:oracle:thin:@mycomp:1522/db1"
        ...
        statement => "UPDATE my_table SET delete='T' WHERE delete='Y'"
       }
}
output {
    stdout { codec => rubydebug }
    if [type] == "actionA" {
        elasticsearch {
            action => "delete"
            index => "contacts"
            document_type => "contact"
            document_id => "%{id}"
            hosts => ["http://localhost:9200"]
        }   
    }
    if [type] == "actionB" { }


}

提前致谢

2 个答案:

答案 0 :(得分:0)

您可以利用schedule参数,并使actionA始终在actionB之前运行,例如让actionA每隔一分钟运行一次(0,2,4,6,......)和actionB每隔几分钟运行一次(1,3,5,......)

input {
    jdbc {
        type => "actionA"
        jdbc_validate_connection => true
        jdbc_connection_string => "jdbc:oracle:thin:@mycomp:1522/db1"
        ...
        schedule => "*/2 * * * *" # run every even minutes
        statement => "SELECT ID FROM my_table WHERE delete='Y'"
       }

    jdbc {
        type => "actionB"
        jdbc_validate_connection => true
        jdbc_connection_string => "jdbc:oracle:thin:@mycomp:1522/db1"
        ...
        schedule => "1-59/2 * * * *" # run every odd minutes
        statement => "UPDATE my_table SET delete='T' WHERE delete='Y'"
       }
}

答案 1 :(得分:0)

有一个技巧。

将您的操作放在单独的文件中,因此每个文件都如下所示:

# action_X.conf
input {
    jdbc {
        # ...
    }
}
output {
    # ...
}

然后为每个文件手动执行logstash:

logstash -f action_a.conf
logstash -f action_b.conf

要定期重复,您可以将上述命令放在shell脚本中,并将该脚本添加到crontab