Нема описа
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.

exchange_functions.go 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package functions
  2. import (
  3. "time"
  4. "git.x2erp.com/qdy/go-base/types"
  5. "git.x2erp.com/qdy/go-db/factory/rabbitmq"
  6. )
  7. // CreateExchange 创建交换机
  8. func CreateExchange(rabbitFactory *rabbitmq.RabbitMQFactory, req types.ExchangeRequest) *types.QueryResult {
  9. // 设置默认值
  10. if req.ChannelName == "" {
  11. req.ChannelName = "default"
  12. }
  13. if req.ExchangeType == "" {
  14. req.ExchangeType = "direct"
  15. }
  16. // 确保通道存在
  17. _, err := rabbitFactory.CreateChannel(req.ChannelName)
  18. if err != nil {
  19. return &types.QueryResult{
  20. Success: false,
  21. Error: "Failed to create channel: " + err.Error(),
  22. Time: time.Now().Format(time.RFC3339),
  23. }
  24. }
  25. // 创建交换机
  26. err = rabbitFactory.AddExchange(
  27. req.ChannelName,
  28. req.ExchangeName,
  29. req.ExchangeType,
  30. req.Durable,
  31. )
  32. if err != nil {
  33. return &types.QueryResult{
  34. Success: false,
  35. Error: "Failed to create exchange: " + err.Error(),
  36. Time: time.Now().Format(time.RFC3339),
  37. }
  38. }
  39. return &types.QueryResult{
  40. Success: true,
  41. Message: "Exchange created successfully",
  42. Time: time.Now().Format(time.RFC3339),
  43. Data: map[string]interface{}{
  44. "exchange_name": req.ExchangeName,
  45. "exchange_type": req.ExchangeType,
  46. "durable": req.Durable,
  47. "channel": req.ChannelName,
  48. },
  49. }
  50. }