|
|
@ -18,7 +18,10 @@ import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"os/signal"
|
|
|
|
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"sync"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
|
@ -30,7 +33,7 @@ import (
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/tools/log"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/controller"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/db/controller"
|
|
|
@ -51,11 +54,13 @@ func StartTransfer(prometheusPort int) error {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mongo, err := unrelation.NewMongo()
|
|
|
|
mongo, err := unrelation.NewMongo()
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := mongo.CreateMsgIndex(); err != nil {
|
|
|
|
|
|
|
|
|
|
|
|
if err = mongo.CreateMsgIndex(); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
client, err := kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
|
|
|
client, err := kdisc.NewDiscoveryRegister(config.Config.Envs.Discovery)
|
|
|
@ -66,6 +71,7 @@ func StartTransfer(prometheusPort int) error {
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := client.CreateRpcRootNodes(config.Config.GetServiceNames()); err != nil {
|
|
|
|
if err := client.CreateRpcRootNodes(config.Config.GetServiceNames()); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -103,26 +109,62 @@ func NewMsgTransfer(msgDatabase controller.CommonMsgDatabase, conversationRpcCli
|
|
|
|
|
|
|
|
|
|
|
|
func (m *MsgTransfer) Start(prometheusPort int) error {
|
|
|
|
func (m *MsgTransfer) Start(prometheusPort int) error {
|
|
|
|
ctx := context.Background()
|
|
|
|
ctx := context.Background()
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
|
|
|
fmt.Println("start msg transfer", "prometheusPort:", prometheusPort)
|
|
|
|
fmt.Println("start msg transfer", "prometheusPort:", prometheusPort)
|
|
|
|
if prometheusPort <= 0 {
|
|
|
|
if prometheusPort <= 0 {
|
|
|
|
return errs.Wrap(errors.New("prometheusPort not correct"))
|
|
|
|
return errs.Wrap(errors.New("prometheusPort not correct"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
go m.historyCH.historyConsumerGroup.RegisterHandleAndConsumer(ctx, m.historyCH)
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
go m.historyMongoCH.historyConsumerGroup.RegisterHandleAndConsumer(ctx, m.historyMongoCH)
|
|
|
|
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m.historyCH.historyConsumerGroup.RegisterHandleAndConsumer(ctx, m.historyCH)
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
|
|
|
defer wg.Done()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m.historyMongoCH.historyConsumerGroup.RegisterHandleAndConsumer(ctx, m.historyMongoCH)
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
if config.Config.Prometheus.Enable {
|
|
|
|
if config.Config.Prometheus.Enable {
|
|
|
|
reg := prometheus.NewRegistry()
|
|
|
|
go func() {
|
|
|
|
reg.MustRegister(
|
|
|
|
proreg := prometheus.NewRegistry()
|
|
|
|
|
|
|
|
proreg.MustRegister(
|
|
|
|
collectors.NewGoCollector(),
|
|
|
|
collectors.NewGoCollector(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
reg.MustRegister(prommetrics.GetGrpcCusMetrics("Transfer")...)
|
|
|
|
proreg.MustRegister(prommetrics.GetGrpcCusMetrics("Transfer")...)
|
|
|
|
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg}))
|
|
|
|
http.Handle("/metrics", promhttp.HandlerFor(proreg, promhttp.HandlerOpts{Registry: proreg}))
|
|
|
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", prometheusPort), nil))
|
|
|
|
err := http.ListenAndServe(fmt.Sprintf(":%d", prometheusPort), nil)
|
|
|
|
|
|
|
|
if err != nil && err != http.ErrServerClosed {
|
|
|
|
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
////////////////////////////////////////
|
|
|
|
}()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
|
|
|
|
|
|
|
<-sigs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// graceful close kafka client.
|
|
|
|
|
|
|
|
go m.historyCH.historyConsumerGroup.Close()
|
|
|
|
|
|
|
|
go m.historyMongoCH.historyConsumerGroup.Close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
done := make(chan struct{}, 1)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
wg.Wait()
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
close(done)
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
|
|
|
case <-done:
|
|
|
|
|
|
|
|
log.ZInfo(context.Background(), "msgtrasfer exit successfully")
|
|
|
|
|
|
|
|
case <-time.After(15 * time.Second):
|
|
|
|
|
|
|
|
log.ZError(context.Background(), "msgtransfer force to exit, timeout 15s", nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|