Scheduler Java plugin Logstash

I need to use scheduler in custom plugin written in Java for Logstash. How is possible to implement this thing?

Thank you

Schedule is a plugin option, if the custom plugin has an option to schedule, then you can use it, if it has not, then there is nothing in Logstash that does that, you would need to schedule the Logstash service itself.

I tried to use the Java Timer for this but doesn't work. The pipeline execute the code but termite after few seconds.

    public void start(Consumer<Map<String, Object>> consumer) {

        // The start method should push Map<String, Object> instances to the supplied QueueWriter
        // instance. Those will be converted to Event instances later in the Logstash event
        // processing pipeline.
        // Inputs that operate on unbounded streams of data or that poll indefinitely for new
        // events should loop indefinitely until they receive a stop request. Inputs that produce
        // a finite sequence of events should loop until that sequence is exhausted or until they
        // receive a stop request, whichever comes first.
        Timer timer = new Timer("Logstash Plugin");
        timer.scheduleAtFixedRate(mymethod, 0L, 300000);

This is more a Java development question than a Logstash one, you need to look how to implement a schedule on a Java code.

You could look at the code of some plugins that have schedule, like the jdbc input, to see how it is done, but I don't think it will be much help because they are written in Ruby.

Thank you for the answers, but i know how to implement a schedule in Java but this doesn't work when i create the plugin logstash and i lanuch the pipeline.

What kind of plugin it is, input, codec, filter or output?

I'm not sure if an Schedule would be supported anywhere else besides the input.

Maybe in your case it would be better to open an issue in the respective repo.

The plugin i have written is input. I try to open an issue. Thank you

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.