|
|
@ -14,11 +14,10 @@ import (
|
|
|
|
"zero/core/lang"
|
|
|
|
"zero/core/lang"
|
|
|
|
"zero/core/logx"
|
|
|
|
"zero/core/logx"
|
|
|
|
"zero/core/queue"
|
|
|
|
"zero/core/queue"
|
|
|
|
"zero/core/redisqueue"
|
|
|
|
|
|
|
|
"zero/core/stores/redis"
|
|
|
|
"zero/core/stores/redis"
|
|
|
|
"zero/core/threading"
|
|
|
|
"zero/core/threading"
|
|
|
|
"zero/rq/constant"
|
|
|
|
"zero/rq/internal"
|
|
|
|
"zero/rq/update"
|
|
|
|
"zero/rq/internal/update"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
const (
|
|
|
@ -155,7 +154,7 @@ func (pusher *Pusher) failover(server string) error {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if option == constant.TimedQueueType {
|
|
|
|
if option == internal.TimedQueueType {
|
|
|
|
message, err = unwrapTimedMessage(message)
|
|
|
|
message, err = unwrapTimedMessage(message)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
logx.Errorf("invalid timedMessage: %s, error: %s", message, err.Error())
|
|
|
|
logx.Errorf("invalid timedMessage: %s, error: %s", message, err.Error())
|
|
|
@ -179,11 +178,11 @@ func UnmarshalPusher(server string) (queue.QueuePusher, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if option == constant.TimedQueueType {
|
|
|
|
if option == internal.TimedQueueType {
|
|
|
|
return redisqueue.NewPusher(store, key, redisqueue.WithTime()), nil
|
|
|
|
return internal.NewPusher(store, key, internal.WithTime()), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return redisqueue.NewPusher(store, key), nil
|
|
|
|
return internal.NewPusher(store, key), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func WithBatchConsistentStrategy(keysFn KeysFn, assembleFn AssembleFn, opts ...discov.BalanceOption) PusherOption {
|
|
|
|
func WithBatchConsistentStrategy(keysFn KeysFn, assembleFn AssembleFn, opts ...discov.BalanceOption) PusherOption {
|
|
|
@ -375,15 +374,15 @@ func getName(key string) string {
|
|
|
|
func newPusher(server string) (queue.QueuePusher, error) {
|
|
|
|
func newPusher(server string) (queue.QueuePusher, error) {
|
|
|
|
if rds, key, option, err := newRedisWithKey(server); err != nil {
|
|
|
|
if rds, key, option, err := newRedisWithKey(server); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
} else if option == constant.TimedQueueType {
|
|
|
|
} else if option == internal.TimedQueueType {
|
|
|
|
return redisqueue.NewPusher(rds, key, redisqueue.WithTime()), nil
|
|
|
|
return internal.NewPusher(rds, key, internal.WithTime()), nil
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return redisqueue.NewPusher(rds, key), nil
|
|
|
|
return internal.NewPusher(rds, key), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func newRedisWithKey(server string) (rds *redis.Redis, key, option string, err error) {
|
|
|
|
func newRedisWithKey(server string) (rds *redis.Redis, key, option string, err error) {
|
|
|
|
fields := strings.Split(server, constant.Delimeter)
|
|
|
|
fields := strings.Split(server, internal.Delimeter)
|
|
|
|
if len(fields) < etcdRedisFields {
|
|
|
|
if len(fields) < etcdRedisFields {
|
|
|
|
err = fmt.Errorf("wrong redis queue: %s, should be ip:port/type/password/key/[option]", server)
|
|
|
|
err = fmt.Errorf("wrong redis queue: %s, should be ip:port/type/password/key/[option]", server)
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -437,7 +436,7 @@ func broadcast(servers []string, message string) error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func unwrapTimedMessage(message string) (string, error) {
|
|
|
|
func unwrapTimedMessage(message string) (string, error) {
|
|
|
|
var tm redisqueue.TimedMessage
|
|
|
|
var tm internal.TimedMessage
|
|
|
|
if err := jsonx.UnmarshalFromString(message, &tm); err != nil {
|
|
|
|
if err := jsonx.UnmarshalFromString(message, &tm); err != nil {
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|