rabbitmq操作
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.

55 lines
1.1 KiB

3 years ago
  1. package rabbitmq
  2. import (
  3. "encoding/json"
  4. )
  5. /**
  6. * 发送一条api通知消息
  7. * @param exchange 交换机名
  8. * @param extype 消息类型
  9. * @param route 路由key
  10. * @param body 内容
  11. */
  12. func SendNotice(site_id, dbname, msg_id string) error {
  13. msgData := map[string]interface{}{
  14. "site_id": site_id,
  15. "dbname": dbname,
  16. "data": map[string]string{
  17. "msg_id": msg_id,
  18. },
  19. }
  20. msgDataJson, err := json.Marshal(msgData)
  21. if err != nil {
  22. return err
  23. }
  24. return Send("direct", SEND_MSG_EXCHANGE, SEND_API_MSG_KEY, msgDataJson)
  25. }
  26. /**
  27. * 发布订单已支付消息
  28. * @param exchange 交换机名
  29. * @param extype 消息类型
  30. * @param route 路由key
  31. * @param body 内容
  32. */
  33. func SendOrderPayed(site_id, dbname, order_id, order_sn, price string) error {
  34. //发布订单已支付消息
  35. orderData := map[string]interface{}{
  36. "site_id": site_id,
  37. "dbname": dbname,
  38. "data": map[string]string{
  39. "order_id": order_id,
  40. "order_sn": order_sn,
  41. "price": price,
  42. },
  43. }
  44. orderDataJson, _ := json.Marshal(orderData)
  45. return Send("direct", ORDER_EXCHANGE, ORDER_PAYED_KEY, orderDataJson)
  46. }