Component Development

It is recommended to refer to existing components to develop a new component.

public interface

  1. // component lifecycle interface
  2. type Lifecycle interface {
  3. // Initialize component, such as initializing the Kafka connection
  4. Init(context Context)
  5. // Start component. For example, start consuming Kafka
  6. Start()
  7. // Stop component.
  8. Stop()
  9. }
  10. // component description interface
  11. type Describable interface {
  12. // For example, source.
  13. Category() Category
  14. // For example, kafka.
  15. Type() Type
  16. // Customized description
  17. String() string
  18. }
  19. // interface for getting configuration
  20. type Config interface {
  21. // to get configuration
  22. Config() interface{}
  23. }
  24. // Component
  25. type Component interface {
  26. // component lifecycle interface
  27. Lifecycle
  28. // component description interface
  29. Describable
  30. // interface for getting configuration
  31. Config
  32. }

Source Component

The source component is connected to the data source input. To develop a new source plug-in, you need to implement the following interfaces.

  1. // source component interface
  2. type Source interface {
  3. Component
  4. Producer
  5. // Confirm that the sink is successful and then submit.
  6. Commit(events []Event)
  7. }
  8. // Source component needs to implement this producer interface.
  9. type Producer interface {
  10. // docking data source
  11. ProductLoop(productFunc ProductFunc)
  12. }

Sink Component

The sink component is connected to the output end. To develop a new sink plug-in, you need to implement the following interfaces.

  1. // sink component interface
  2. type Sink interface {
  3. Component
  4. Consumer
  5. }
  6. // Sink component needs to implement this consumer interface.
  7. type Consumer interface {
  8. // docking output
  9. Consume(batch Batch) Result
  10. }

Interceptor Component

The interceptor component intercepts events. To develop a new interceptor plug-in, you need to implement the following interfaces.

  1. // interceptor component interface
  2. type Interceptor interface {
  3. Component
  4. // Intercept processing
  5. Intercept(invoker Invoker, invocation Invocation) api.Result
  6. }

Note

Please note that the newly added components need to be registered in the import of pkg/include/include.go.