- Simple Microbatching example written in golang.
- Create struct that implements BatchProcessor Interface such as
type YourBatchProcessor struct {}
func (p *YourBatchProcessor) Process (job microbatch.Job) (microbatch.JobResult, error) {
return microbatch.JobResult{
Result: nil,
JobId: 1,
}, nil
}
- Initiate a new Microbatcher using Factory function. Provide required such as "batchSize" , "frequency" and your batch Processor that you created above.
mb := microbatch.NewMicroBatch(batchSize, yourBatchProcessor, frequency)
- Create a channel to get your successfully ran job results.
jobResult := make(chan microbatch.JobResult{})
- Start MicroBatcher and pass your job result channel.
mb.Run(context.Background(), jobResult)
- Add Jobs to your microbatcher
mb.Submit(microbatch.Job{Id: 1, Task: 10})
For a full implementation with optional configuration, please checkout the example provided in the repo.