Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rabbitmq_config.go 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package subconfigs
  2. import "fmt"
  3. // RabbitMQConfig RabbitMQ配置
  4. type RabbitMQConfig struct {
  5. BaseConfig
  6. Host string `yaml:"host"`
  7. Port int `yaml:"port"`
  8. Username string `yaml:"username"`
  9. Password string `yaml:"password"`
  10. Vhost string `yaml:"vhost"`
  11. UseTLS bool `yaml:"use_tls"`
  12. CACert string `yaml:"ca_cert"`
  13. CertFile string `yaml:"cert_file"`
  14. KeyFile string `yaml:"key_file"`
  15. MaxOpenChannels int `yaml:"max_open_channels"`
  16. ReconnectDelay int `yaml:"reconnect_delay"`
  17. MaxReconnectAttempts int `yaml:"max_reconnect_attempts"`
  18. Heartbeat int `yaml:"heartbeat"`
  19. ChannelSize int `yaml:"channel_size"`
  20. DefaultExchange string `yaml:"default_exchange"`
  21. DefaultQueue string `yaml:"default_queue"`
  22. AutoAck bool `yaml:"auto_ack"`
  23. Mandatory bool `yaml:"mandatory"`
  24. Immediate bool `yaml:"immediate"`
  25. PrefetchCount int `yaml:"prefetch_count"`
  26. PrefetchSize int `yaml:"prefetch_size"`
  27. Global bool `yaml:"global"`
  28. PublisherConfirms bool `yaml:"publisher_confirms"`
  29. ConfirmTimeout int `yaml:"confirm_timeout"`
  30. }
  31. func NewRabbitMQConfig() *RabbitMQConfig {
  32. return &RabbitMQConfig{}
  33. }
  34. func (c *RabbitMQConfig) SetDefaults() {
  35. c.Port = 5672
  36. c.Username = "guest"
  37. c.Password = "guest"
  38. c.Vhost = "/"
  39. c.MaxOpenChannels = 10
  40. c.ReconnectDelay = 5000
  41. c.MaxReconnectAttempts = 10
  42. c.Heartbeat = 30
  43. c.ChannelSize = 100
  44. c.DefaultExchange = "amq.direct"
  45. c.PrefetchCount = 1
  46. c.ConfirmTimeout = 30
  47. }
  48. func (c *RabbitMQConfig) Load(data map[string]interface{}) error {
  49. return c.LoadFromYAML(data, c)
  50. }
  51. func (c *RabbitMQConfig) Validate() error {
  52. if c.Host == "" {
  53. return fmt.Errorf("rabbitmq host is required")
  54. }
  55. if c.Port <= 0 {
  56. return fmt.Errorf("invalid rabbitmq port: %d", c.Port)
  57. }
  58. return nil
  59. }
  60. func (c *RabbitMQConfig) IsConfigured() bool {
  61. return c.Host != ""
  62. }
  63. // 自动注册
  64. func init() {
  65. Register("rabbitmq", &RabbitMQConfig{})
  66. }