-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrpc_template_server.cc
55 lines (41 loc) · 1.63 KB
/
trpc_template_server.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// copyright skylanwei 2023-11-18
#include <string>
#include "trpc/common/trpc_app.h"
#include "trpc_template_service.h"
#include "trpc/util/log/default/default_log.h"
#include "trpc/util/log/default/sinks/local_file/local_file_sink.h"
#include "trpc/common/config/local_file_sink_conf.h"
#include "common/trace_id_formatter.h"
#include "common/include/opentelemetry_telemetry_api.h"
namespace trpc {
namespace sample {
class TrpcTemplateServer : public ::trpc::TrpcApp {
public:
int Initialize() override {
const auto& config = ::trpc::TrpcConfig::GetInstance()->GetServerConfig();
// Set the service name, which must be the same as the value of the `/server/service/name` configuration item
// in the configuration file, otherwise the framework cannot receive requests normally.
std::string service_name = fmt::format("{}.{}.{}.{}", "trpc", config.app, config.server, "TrpcTemplateService");
TRPC_FMT_INFO("service name:{}", service_name);
RegisterService(service_name, std::make_shared<TrpcTemplateServiceImpl>());
return 0;
}
int RegisterPlugins() override {
// Initializes the OpenTelemetry plugin and filters in RegisterPlugins
//add spd custom flag
Log* t = ::trpc::LogFactory::GetInstance()->Get().Get();
DefaultLog* dpt = dynamic_cast<DefaultLog*>(t);
dpt->SetCustomFlag<LocalFileSink, LocalFileSinkConfig, TraceIdFormatter>("default", 'q');
::trpc::opentelemetry::Init();
return 0;
}
void Destroy() override {}
};
} // sample
} // trpc
int main(int argc, char** argv) {
::trpc::sample::TrpcTemplateServer server;
server.Main(argc, argv);
server.Wait();
return 0;
}