Compare commits
4 Commits
v0.3.7
...
api/v0.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01424e4387 | ||
|
|
5e85934e35 | ||
|
|
edbcad5973 | ||
|
|
6711cb7613 |
2
Makefile
2
Makefile
@@ -13,7 +13,7 @@ SRCS_MK := $(foreach dir, app, $(wildcard $(dir)/*/*/Makefile))
|
|||||||
|
|
||||||
# generate protobuf api go code
|
# generate protobuf api go code
|
||||||
api:
|
api:
|
||||||
cd api
|
cd api && \
|
||||||
buf generate
|
buf generate
|
||||||
|
|
||||||
# show help
|
# show help
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -75,19 +75,6 @@ message Data {
|
|||||||
string bucket = 4;
|
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 {
|
message Doris {
|
||||||
string address = 1;
|
string address = 1;
|
||||||
}
|
}
|
||||||
@@ -113,6 +100,74 @@ message Data {
|
|||||||
bool ignore_peer_addr = 10;
|
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
|
Database database = 1; // 数据库DSN
|
||||||
|
|
||||||
Redis redis = 10; // Redis
|
Redis redis = 10; // Redis
|
||||||
@@ -124,5 +179,14 @@ message Data {
|
|||||||
InfluxDB influxdb = 21; // InfluxDB数据库
|
InfluxDB influxdb = 21; // InfluxDB数据库
|
||||||
Doris doris = 22; // Doris数据库
|
Doris doris = 22; // Doris数据库
|
||||||
|
|
||||||
|
// Message Queue
|
||||||
|
|
||||||
Kafka kafka = 30; // Kafka服务
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ func NewApp(ll log.Logger, rr kratosRegistry.Registrar, srv ...transport.Server)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// doBootstrap 执行引导
|
// DoBootstrap 执行引导
|
||||||
func doBootstrap(serviceInfo *config.ServiceInfo) (*conf.Bootstrap, log.Logger, kratosRegistry.Registrar) {
|
func DoBootstrap(serviceInfo *config.ServiceInfo) (*conf.Bootstrap, log.Logger, kratosRegistry.Registrar) {
|
||||||
// inject command flags
|
// inject command flags
|
||||||
Flags := config.NewCommandFlags()
|
Flags := config.NewCommandFlags()
|
||||||
Flags.Init()
|
Flags.Init()
|
||||||
@@ -78,7 +78,7 @@ func Bootstrap(initApp InitApp, serviceName, version *string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// bootstrap
|
// bootstrap
|
||||||
cfg, ll, reg := doBootstrap(Service)
|
cfg, ll, reg := DoBootstrap(Service)
|
||||||
|
|
||||||
// init app
|
// init app
|
||||||
app, cleanup, err := initApp(ll, reg, cfg)
|
app, cleanup, err := initApp(ll, reg, cfg)
|
||||||
|
|||||||
@@ -1,19 +1,57 @@
|
|||||||
package bootstrap
|
package bootstrap
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/go-kratos/kratos/v2"
|
"github.com/go-kratos/kratos/v2"
|
||||||
"github.com/go-kratos/kratos/v2/log"
|
"github.com/go-kratos/kratos/v2/log"
|
||||||
"github.com/go-kratos/kratos/v2/registry"
|
"github.com/go-kratos/kratos/v2/registry"
|
||||||
|
|
||||||
v1 "github.com/tx7do/kratos-bootstrap/api/gen/go/conf/v1"
|
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)
|
app := NewApp(logger, registrar)
|
||||||
return app, func() {
|
return app, func() {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBootstrap(t *testing.T) {
|
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 {
|
func (s *ServiceInfo) GetInstanceId() string {
|
||||||
return s.Id + "." + s.Name
|
return s.Id + "." + s.Name
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user