Compare commits
5 Commits
v0.3.6
...
api/v0.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01424e4387 | ||
|
|
5e85934e35 | ||
|
|
edbcad5973 | ||
|
|
6711cb7613 | ||
|
|
d7b7e9e8fd |
2
Makefile
2
Makefile
@@ -13,7 +13,7 @@ SRCS_MK := $(foreach dir, app, $(wildcard $(dir)/*/*/Makefile))
|
||||
|
||||
# generate protobuf api go code
|
||||
api:
|
||||
cd api
|
||||
cd api && \
|
||||
buf generate
|
||||
|
||||
# show help
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -75,19 +75,6 @@ message Data {
|
||||
string bucket = 4;
|
||||
}
|
||||
|
||||
// Kafka
|
||||
message Kafka {
|
||||
repeated string addrs = 1; // 对端网络地址
|
||||
string codec = 2; // 编解码器
|
||||
bool async = 3; // 异步发送
|
||||
bool allow_auto_topic_creation = 4; // 允许发送的时候自动创建主题
|
||||
int32 batch_size = 5; // 批量发送量
|
||||
google.protobuf.Duration batch_timeout = 6; // 批量发送超时时间
|
||||
google.protobuf.Duration read_timeout = 7; // 读取超时时间
|
||||
google.protobuf.Duration write_timeout = 8; // 发送超时时间
|
||||
int64 batch_bytes = 9;// 批量发送字节数
|
||||
}
|
||||
|
||||
message Doris {
|
||||
string address = 1;
|
||||
}
|
||||
@@ -113,6 +100,74 @@ message Data {
|
||||
bool ignore_peer_addr = 10;
|
||||
}
|
||||
|
||||
message Snowflake {
|
||||
|
||||
}
|
||||
|
||||
// Kafka
|
||||
message Kafka {
|
||||
repeated string addrs = 1; // 对端网络地址
|
||||
|
||||
string codec = 2; // 编解码器
|
||||
|
||||
bool async = 3; // 异步发送
|
||||
bool allow_auto_topic_creation = 4; // 允许发送的时候自动创建主题
|
||||
|
||||
int32 batch_size = 5; // 批量发送量
|
||||
int64 batch_bytes = 6;// 批量发送字节数
|
||||
|
||||
google.protobuf.Duration batch_timeout = 7; // 批量发送超时时间
|
||||
google.protobuf.Duration read_timeout = 8; // 读取超时时间
|
||||
google.protobuf.Duration write_timeout = 9; // 发送超时时间
|
||||
}
|
||||
|
||||
// RabbitMQ
|
||||
message RabbitMQ {
|
||||
repeated string addrs = 1; // 对端网络地址
|
||||
}
|
||||
|
||||
// MQTT
|
||||
message Mqtt {
|
||||
string addr = 1; // 对端网络地址
|
||||
}
|
||||
|
||||
message ActiveMQ {
|
||||
string endpoint = 1; // 对端网络地址
|
||||
string codec = 2; // 编解码器: json,xml,yaml...
|
||||
}
|
||||
|
||||
message NATS {
|
||||
string endpoint = 1; // 对端网络地址
|
||||
string codec = 2; // 编解码器: json,xml,yaml...
|
||||
}
|
||||
|
||||
message NSQ {
|
||||
string endpoint = 1; // 对端网络地址
|
||||
string codec = 2; // 编解码器: json,xml,yaml...
|
||||
}
|
||||
|
||||
message Pulsar {
|
||||
string endpoint = 1; // 对端网络地址
|
||||
string codec = 2; // 编解码器: json,xml,yaml...
|
||||
}
|
||||
|
||||
message RocketMQ {
|
||||
string version = 1; // 驱动版本:aliyun、v2、v5
|
||||
string codec = 2; // 编解码器: json,xml,yaml...
|
||||
bool enable_trace = 3;
|
||||
|
||||
repeated string name_servers = 4;
|
||||
string name_server_domain = 5;
|
||||
|
||||
string access_key = 6;
|
||||
string secret_key = 7;
|
||||
string security_token = 8;
|
||||
|
||||
string namespace = 9;
|
||||
string instance_name = 10;
|
||||
string group_name = 11;
|
||||
}
|
||||
|
||||
Database database = 1; // 数据库DSN
|
||||
|
||||
Redis redis = 10; // Redis
|
||||
@@ -124,5 +179,14 @@ message Data {
|
||||
InfluxDB influxdb = 21; // InfluxDB数据库
|
||||
Doris doris = 22; // Doris数据库
|
||||
|
||||
// Message Queue
|
||||
|
||||
Kafka kafka = 30; // Kafka服务
|
||||
RabbitMQ rabbitmq = 31; // RabbitMQ服务
|
||||
Mqtt mqtt = 32; // MQTT服务
|
||||
ActiveMQ activemq = 33; // ActiveMQ
|
||||
NATS nats = 34; // NATS
|
||||
NSQ nsq = 35; // NATS
|
||||
Pulsar pulsar = 36; // Pulsar
|
||||
RocketMQ rocketmq = 38; // RocketMQ
|
||||
}
|
||||
|
||||
21
bootstrap.go
21
bootstrap.go
@@ -24,6 +24,7 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
// NewApp 创建应用程序
|
||||
func NewApp(ll log.Logger, rr kratosRegistry.Registrar, srv ...transport.Server) *kratos.App {
|
||||
return kratos.New(
|
||||
kratos.ID(Service.GetInstanceId()),
|
||||
@@ -38,8 +39,8 @@ func NewApp(ll log.Logger, rr kratosRegistry.Registrar, srv ...transport.Server)
|
||||
)
|
||||
}
|
||||
|
||||
// doBootstrap 应用引导启动
|
||||
func doBootstrap(serviceInfo *config.ServiceInfo) (*conf.Bootstrap, log.Logger, kratosRegistry.Registrar) {
|
||||
// DoBootstrap 执行引导
|
||||
func DoBootstrap(serviceInfo *config.ServiceInfo) (*conf.Bootstrap, log.Logger, kratosRegistry.Registrar) {
|
||||
// inject command flags
|
||||
Flags := config.NewCommandFlags()
|
||||
Flags.Init()
|
||||
@@ -67,16 +68,26 @@ func doBootstrap(serviceInfo *config.ServiceInfo) (*conf.Bootstrap, log.Logger,
|
||||
|
||||
type InitApp func(logger log.Logger, registrar kratosRegistry.Registrar, bootstrap *conf.Bootstrap) (*kratos.App, func(), error)
|
||||
|
||||
func Bootstrap(initApp InitApp) {
|
||||
// bootstrap
|
||||
cfg, ll, reg := doBootstrap(Service)
|
||||
// Bootstrap 应用引导启动
|
||||
func Bootstrap(initApp InitApp, serviceName, version *string) {
|
||||
if serviceName != nil && len(*serviceName) != 0 {
|
||||
Service.Name = *serviceName
|
||||
}
|
||||
if version != nil && len(*version) != 0 {
|
||||
Service.Version = *version
|
||||
}
|
||||
|
||||
// bootstrap
|
||||
cfg, ll, reg := DoBootstrap(Service)
|
||||
|
||||
// init app
|
||||
app, cleanup, err := initApp(ll, reg, cfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
// run the app.
|
||||
if err = app.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -1,19 +1,57 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/go-kratos/kratos/v2"
|
||||
"github.com/go-kratos/kratos/v2/log"
|
||||
"github.com/go-kratos/kratos/v2/registry"
|
||||
|
||||
v1 "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
|
||||
"testing"
|
||||
"github.com/tx7do/kratos-bootstrap/config"
|
||||
)
|
||||
|
||||
func initApp(logger log.Logger, registrar registry.Registrar, bootstrap *v1.Bootstrap) (*kratos.App, func(), error) {
|
||||
func initApp(logger log.Logger, registrar registry.Registrar, _ *v1.Bootstrap) (*kratos.App, func(), error) {
|
||||
app := NewApp(logger, registrar)
|
||||
return app, func() {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestBootstrap(t *testing.T) {
|
||||
Bootstrap(initApp)
|
||||
serviceName := "test"
|
||||
version := "v0.0.1"
|
||||
Bootstrap(initApp, &serviceName, &version)
|
||||
}
|
||||
|
||||
type CustomConfig struct {
|
||||
Cfg string `protobuf:"bytes,1,opt,name=cfg,proto3" json:"cfg,omitempty"`
|
||||
}
|
||||
|
||||
func initAppEx(logger log.Logger, registrar registry.Registrar, _ *v1.Bootstrap, _ *CustomConfig) (*kratos.App, func(), error) {
|
||||
app := NewApp(logger, registrar)
|
||||
return app, func() {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestCustomBootstrap(t *testing.T) {
|
||||
customCfg := &CustomConfig{}
|
||||
config.RegisterConfig(customCfg)
|
||||
|
||||
Service.SetName("test")
|
||||
Service.SetVersion("v0.0.1")
|
||||
|
||||
// bootstrap
|
||||
cfg, ll, reg := DoBootstrap(Service)
|
||||
|
||||
// init app
|
||||
app, cleanup, err := initAppEx(ll, reg, cfg, customCfg)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
// run the app.
|
||||
if err = app.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,14 @@ func NewServiceInfo(name, version, id string) *ServiceInfo {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServiceInfo) SetName(name string) {
|
||||
s.Name = name
|
||||
}
|
||||
|
||||
func (s *ServiceInfo) SetVersion(version string) {
|
||||
s.Version = version
|
||||
}
|
||||
|
||||
func (s *ServiceInfo) GetInstanceId() string {
|
||||
return s.Id + "." + s.Name
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user