seaweedfs/weed/mq/msgclient/config.go

64 lines
1.5 KiB
Go
Raw Normal View History

2020-05-18 00:34:10 +00:00
package msgclient
import (
"context"
"log"
2022-07-02 05:43:25 +00:00
"github.com/chrislusf/seaweedfs/weed/mq/broker"
2020-05-18 00:34:10 +00:00
"github.com/chrislusf/seaweedfs/weed/pb"
2022-07-02 05:43:25 +00:00
"github.com/chrislusf/seaweedfs/weed/pb/mq_pb"
2020-05-18 00:34:10 +00:00
)
func (mc *MessagingClient) configureTopic(tp broker.TopicPartition) error {
2022-07-02 05:43:25 +00:00
return mc.withAnyBroker(func(client mq_pb.SeaweedMessagingClient) error {
2020-05-18 00:34:10 +00:00
_, err := client.ConfigureTopic(context.Background(),
2022-07-02 05:43:25 +00:00
&mq_pb.ConfigureTopicRequest{
2020-05-18 00:34:10 +00:00
Namespace: tp.Namespace,
Topic: tp.Topic,
2022-07-02 05:43:25 +00:00
Configuration: &mq_pb.TopicConfiguration{
2020-05-18 00:34:10 +00:00
PartitionCount: 0,
Collection: "",
Replication: "",
IsTransient: false,
Partitoning: 0,
},
})
return err
})
}
func (mc *MessagingClient) DeleteTopic(namespace, topic string) error {
2022-07-02 05:43:25 +00:00
return mc.withAnyBroker(func(client mq_pb.SeaweedMessagingClient) error {
2020-05-18 00:34:10 +00:00
_, err := client.DeleteTopic(context.Background(),
2022-07-02 05:43:25 +00:00
&mq_pb.DeleteTopicRequest{
2020-05-18 00:34:10 +00:00
Namespace: namespace,
Topic: topic,
})
return err
})
}
2022-07-02 05:43:25 +00:00
func (mc *MessagingClient) withAnyBroker(fn func(client mq_pb.SeaweedMessagingClient) error) error {
2020-05-18 00:34:10 +00:00
var lastErr error
for _, broker := range mc.bootstrapBrokers {
grpcConnection, err := pb.GrpcDial(context.Background(), broker, mc.grpcDialOption)
if err != nil {
log.Printf("dial broker %s: %v", broker, err)
continue
}
defer grpcConnection.Close()
2022-07-02 05:43:25 +00:00
err = fn(mq_pb.NewSeaweedMessagingClient(grpcConnection))
2020-05-18 00:34:10 +00:00
if err == nil {
return nil
}
lastErr = err
}
return lastErr
}