factory.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package solacereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/solacereceiver"
  4. import (
  5. "context"
  6. "time"
  7. "go.opentelemetry.io/collector/component"
  8. "go.opentelemetry.io/collector/config/configtls"
  9. "go.opentelemetry.io/collector/consumer"
  10. "go.opentelemetry.io/collector/receiver"
  11. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/solacereceiver/internal/metadata"
  12. )
  13. const (
  14. // default value for max unaked messages
  15. defaultMaxUnaked int32 = 1000
  16. // default value for host
  17. defaultHost string = "localhost:5671"
  18. )
  19. // NewFactory creates a factory for Solace receiver.
  20. func NewFactory() receiver.Factory {
  21. return receiver.NewFactory(
  22. metadata.Type,
  23. createDefaultConfig,
  24. receiver.WithTraces(createTracesReceiver, metadata.TracesStability),
  25. )
  26. }
  27. // createDefaultConfig creates the default configuration for receiver.
  28. func createDefaultConfig() component.Config {
  29. return &Config{
  30. Broker: []string{defaultHost},
  31. MaxUnacked: defaultMaxUnaked,
  32. Auth: Authentication{},
  33. TLS: configtls.TLSClientSetting{
  34. InsecureSkipVerify: false,
  35. Insecure: false,
  36. },
  37. Flow: FlowControl{
  38. DelayedRetry: &FlowControlDelayedRetry{
  39. Delay: 10 * time.Millisecond,
  40. },
  41. },
  42. }
  43. }
  44. // CreateTracesReceiver creates a trace receiver based on provided config. Component is not shared
  45. func createTracesReceiver(
  46. _ context.Context,
  47. params receiver.CreateSettings,
  48. receiverConfig component.Config,
  49. nextConsumer consumer.Traces,
  50. ) (receiver.Traces, error) {
  51. cfg, ok := receiverConfig.(*Config)
  52. if !ok {
  53. return nil, component.ErrDataTypeIsNotSupported
  54. }
  55. // pass cfg, params and next consumer through
  56. return newTracesReceiver(cfg, params, nextConsumer)
  57. }