88 lines
1.9 KiB
Go
88 lines
1.9 KiB
Go
package data
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"voucher/internal/conf"
|
|
"voucher/internal/pkg/mq"
|
|
)
|
|
|
|
func Test_OrderProducer(t *testing.T) {
|
|
m := make(map[string]*conf.EventMap)
|
|
|
|
m["order"] = &conf.EventMap{
|
|
Topic: "voucher_order_order",
|
|
}
|
|
|
|
c := &conf.RocketMQ{
|
|
Addr: "http://rmq-cn-nwy3fn4ex09.cn-chengdu.rmq.aliyuncs.com:8080",
|
|
AccessKey: "Qecl4cea2IAZPKoD",
|
|
SecretKey: "Z3596KCFA9RAUR6k",
|
|
SecretToken: "",
|
|
EventMap: m,
|
|
}
|
|
|
|
mqx, err := buildMqProducer(c)
|
|
if err != nil {
|
|
t.Errorf("buildMqProducer() error = %v", err)
|
|
return
|
|
}
|
|
|
|
ctx := context.Background()
|
|
orderNo := ""
|
|
|
|
eventMap := c.EventMap["order"]
|
|
sendOption := []mq.SendOption{
|
|
mq.WithSendShardingKeysOption(orderNo),
|
|
}
|
|
|
|
if err = mqx.SendSync(ctx, eventMap.Topic, []byte("{}"), sendOption...); err != nil {
|
|
t.Errorf("入队失败 error = %v", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
func Test_NotifyProducer(t *testing.T) {
|
|
m := make(map[string]*conf.EventMap)
|
|
|
|
m["notifyRetry"] = &conf.EventMap{
|
|
Topic: "voucher_order_notifyRetry",
|
|
}
|
|
|
|
//c := &conf.RocketMQ{
|
|
// Addr: "http://rmq-cn-nwy3fn4ex09.cn-chengdu.rmq.aliyuncs.com:8080",
|
|
// AccessKey: "Qecl4cea2IAZPKoD",
|
|
// SecretKey: "Z3596KCFA9RAUR6k",
|
|
// SecretToken: "",
|
|
// EventMap: m,
|
|
//}
|
|
|
|
c := &conf.RocketMQ{
|
|
Addr: "http://rmq-cn-j4g3zpaiz06-vpc.cn-beijing.rmq.aliyuncs.com:8080",
|
|
AccessKey: "X3Dc7lRupY2bWc91",
|
|
SecretKey: "5G4h85f4my10P4vK",
|
|
SecretToken: "",
|
|
EventMap: m,
|
|
}
|
|
|
|
mqx, err := buildMqProducer(c)
|
|
if err != nil {
|
|
t.Errorf("buildMqProducer() error = %v", err)
|
|
return
|
|
}
|
|
|
|
ctx := context.Background()
|
|
shardingKey := "22"
|
|
|
|
eventMap := c.EventMap["notifyRetry"]
|
|
sendOption := []mq.SendOption{
|
|
mq.WithSendShardingKeysOption(shardingKey),
|
|
mq.WithSendDelayLevelOption(0),
|
|
}
|
|
|
|
if err = mqx.SendSync(ctx, eventMap.Topic, []byte("{}"), sendOption...); err != nil {
|
|
t.Errorf("回调通知入队失败 error = %v", err)
|
|
return
|
|
}
|
|
}
|