Skip to content

Commit

Permalink
Change name to frpc
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasy-peak committed Apr 10, 2024
1 parent 35fa7b5 commit 2a6dfce
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 153 deletions.
96 changes: 48 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# brpc
# frpc
*An rpc code generation framework for c++, It supports c++17/20/23*

[![](https://github.com/fantasy-peak/brpc/workflows/ubuntu-gcc13/badge.svg)](https://github.com/fantasy-peak/brpc/actions)
[![](https://github.com/fantasy-peak/frpc/workflows/ubuntu-gcc13/badge.svg)](https://github.com/fantasy-peak/frpc/actions)

## Support this repository:

Expand All @@ -15,10 +15,10 @@ To run the application, run the following command:

```
1. Check local g++ version, need g++ version >= gcc version 13.1.0 (GCC)
2. git clone https://github.com/fantasy-peak/brpc.git
2. git clone https://github.com/fantasy-peak/frpc.git
3. xmake build -v -y
4. xmake install -o .
5. ./bin/brpc -f ./config/config.yaml -t ./template/cpp -o ./out
5. ./bin/frpc -f ./config/config.yaml -t ./template/cpp -o ./out
// compile and run test
6. xmake build -v -y --file=./test_xmake.lua
7. xmake install -o . --file=./test_xmake.lua
Expand Down Expand Up @@ -48,8 +48,8 @@ It uses yaml to define interface data, Then generate a header file library.

```
property:
filename: brpc.hpp # Generate the name of the header file library
namespace: brpc # c++ namespace name
filename: frpc.hpp # Generate the name of the header file library
namespace: frpc # c++ namespace name
Info:
type: struct
Expand Down Expand Up @@ -105,26 +105,26 @@ Stream:
```

## c++17 callback example
### bi (zmq router and zmq dealer) brpc server example
### bi (zmq router and zmq dealer) frpc server example

```
brpc::ChannelConfig bi_config{};
frpc::ChannelConfig bi_config{};
bi_config.addr = "tcp://127.0.0.1:5878";
auto server = brpc::HelloWorldServer::create(
auto server = frpc::HelloWorldServer::create(
bi_config,
std::make_shared<Handler>(),
[](std::string error) {
spdlog::error("brpc::HelloWorldServer error: {}", error);
spdlog::error("frpc::HelloWorldServer error: {}", error);
});
server->start();
```

### bi (zmq router and zmq dealer) brpc client example
### bi (zmq router and zmq dealer) frpc client example
```
brpc::ChannelConfig bi_config{};
frpc::ChannelConfig bi_config{};
bi_config.addr = "tcp://127.0.0.1:5878";
auto client = brpc::HelloWorldClient::create(bi_config, [](std::string error) {
spdlog::error("brpc::HelloWorldClient error: {}", error);
auto client = frpc::HelloWorldClient::create(bi_config, [](std::string error) {
spdlog::error("frpc::HelloWorldClient error: {}", error);
});
client->start();
Expand All @@ -133,27 +133,27 @@ client->hello_world(
create_bank_info(),
bank_name,
999,
[](std::string reply, brpc::Info info, uint64_t count) {
spdlog::info("brpc::HelloWorldClient::hello_world recv: {},{},{}", reply, brpc::toString(info), count);
[](std::string reply, frpc::Info info, uint64_t count) {
spdlog::info("frpc::HelloWorldClient::hello_world recv: {},{},{}", reply, frpc::toString(info), count);
});
// set timeout 200 milliseconds
client->hello_world(
create_bank_info(),
bank_name,
999,
[](std::string reply, brpc::Info info, uint64_t count) {
spdlog::info("brpc::HelloWorldClient::hello_world(timeout) recv: {},{},{}", reply, brpc::toString(info), count);
[](std::string reply, frpc::Info info, uint64_t count) {
spdlog::info("frpc::HelloWorldClient::hello_world(timeout) recv: {},{},{}", reply, frpc::toString(info), count);
},
std::chrono::milliseconds(200),
[] {
spdlog::info("brpc::HelloWorldClient::timeout timeout!!!");
spdlog::info("frpc::HelloWorldClient::timeout timeout!!!");
});
```

### uni (zmq pub and zmq sub) brpc server example
### uni (zmq pub and zmq sub) frpc server example
```
struct HelloWorldReceiverHandler : public brpc::HelloWorldReceiverHandler {
struct HelloWorldReceiverHandler : public frpc::HelloWorldReceiverHandler {
virtual void hello_world(std::string in) override {
spdlog::info("HelloWorldReceiverHandler::hello_world: {}", in);
return;
Expand All @@ -163,9 +163,9 @@ struct HelloWorldReceiverHandler : public brpc::HelloWorldReceiverHandler {
return;
}
};
brpc::ChannelConfig sub_config{};
frpc::ChannelConfig sub_config{};
sub_config.addr = "tcp://127.0.0.1:5877";
auto receiver = brpc::HelloWorldReceiver::create(
auto receiver = frpc::HelloWorldReceiver::create(
sub_config,
std::make_shared<HelloWorldReceiverHandler>(),
[](auto error) {
Expand All @@ -174,14 +174,14 @@ auto receiver = brpc::HelloWorldReceiver::create(
receiver->start();
```

### uni (zmq pub and zmq sub) brpc clinet example
### uni (zmq pub and zmq sub) frpc clinet example
```
brpc::ChannelConfig pub_config{};
frpc::ChannelConfig pub_config{};
pub_config.addr = "tcp://127.0.0.1:5877";
auto sender = brpc::HelloWorldSender::create(pub_config);
auto sender = frpc::HelloWorldSender::create(pub_config);
int i = 10;
while (i--) {
sender->hello_world(std::to_string(i) + "_brpc");
sender->hello_world(std::to_string(i) + "_frpc");
sender->notice(i, "hello world");
std::this_thread::sleep_for(std::chrono::seconds(1));
}
Expand All @@ -190,63 +190,63 @@ while (i--) {


## c++20 coroutine example(It relies on independent asio)
### bi (zmq router and zmq dealer) brpc server example
### bi (zmq router and zmq dealer) frpc server example

```
struct CoroHandler : public brpc::CoroHelloWorldServerHandler {
struct CoroHandler : public frpc::CoroHelloWorldServerHandler {
virtual asio::awaitable<void> hello_world(
brpc::BankInfo bank_info,
frpc::BankInfo bank_info,
std::string bank_name,
uint64_t blance,
std::function<void(std::string, brpc::Info, uint64_t)> cb) override {
spdlog::info("coro brpc::HelloWorldServer server recv: {}, bank_name: {}, blance: {}",
brpc::toString(bank_info), bank_name, blance);
brpc::Info info;
std::function<void(std::string, frpc::Info, uint64_t)> cb) override {
spdlog::info("coro frpc::HelloWorldServer server recv: {}, bank_name: {}, blance: {}",
frpc::toString(bank_info), bank_name, blance);
frpc::Info info;
info.name = "coro test";
cb("coro hello world", std::move(info), 556);
co_return;
}
};
brpc::ChannelConfig bi_config{};
frpc::ChannelConfig bi_config{};
bi_config.addr = "tcp://127.0.0.1:5879";
auto server = brpc::HelloWorldServer::create(
auto server = frpc::HelloWorldServer::create(
bi_config,
std::make_shared<CoroHandler>(),
[](std::string error) {
spdlog::error("brpc::HelloWorldServer error: {}", error);
spdlog::error("frpc::HelloWorldServer error: {}", error);
});
server->start();
```

### bi (zmq router and zmq dealer) brpc client example
### bi (zmq router and zmq dealer) frpc client example
```
asio::co_spawn(pool.getIoContext(), [&]() -> asio::awaitable<void> {
std::cout << std::this_thread::get_id() << std::endl;
brpc::ChannelConfig bi_config{};
frpc::ChannelConfig bi_config{};
bi_config.addr = "tcp://127.0.0.1:5879";
auto client = brpc::HelloWorldClient::create(bi_config, [](std::string error) {
spdlog::error("coro brpc::HelloWorldClient error: {}", error);
auto client = frpc::HelloWorldClient::create(bi_config, [](std::string error) {
spdlog::error("coro frpc::HelloWorldClient error: {}", error);
});
client->start();
spdlog::info("start coro client.");
auto [reply, info, count] = co_await client->hello_world_coro(create_bank_info(), "HF", 777, asio::as_tuple(asio::use_awaitable));
spdlog::info("coro brpc::HelloWorldClient::hello_world recv: {},{},{}", reply, brpc::toString(info), count);
spdlog::info("coro frpc::HelloWorldClient::hello_world recv: {},{},{}", reply, frpc::toString(info), count);
// set timeout
auto ret = co_await client->hello_world_coro(create_bank_info(), "HF", 666, std::chrono::milliseconds{500}, asio::use_awaitable);
if (ret.has_value()) {
auto [reply, info, count] = ret.value();
spdlog::info("coro brpc::HelloWorldClient::hello_world recv: {},{},{}", reply, brpc::toString(info), count);
spdlog::info("coro frpc::HelloWorldClient::hello_world recv: {},{},{}", reply, frpc::toString(info), count);
co_return;
}
spdlog::error("coro brpc::HelloWorldClient::hello_world timeout");
spdlog::error("coro frpc::HelloWorldClient::hello_world timeout");
co_return;
}, asio::detached);
```

### uni (zmq pub and zmq sub) brpc server example
### uni (zmq pub and zmq sub) frpc server example
```
struct CoroHelloWorldReceiver : public brpc::CoroHelloWorldReceiverHandler {
struct CoroHelloWorldReceiver : public frpc::CoroHelloWorldReceiverHandler {
virtual asio::awaitable<void> hello_world(std::string in) override {
spdlog::info("CoroHelloWorldReceiver::hello_world: {}", in);
co_return;
Expand All @@ -256,9 +256,9 @@ struct CoroHelloWorldReceiver : public brpc::CoroHelloWorldReceiverHandler {
co_return;
}
};
brpc::ChannelConfig sub_config{};
frpc::ChannelConfig sub_config{};
sub_config.addr = "tcp://127.0.0.1:5877";
auto receiver = brpc::HelloWorldReceiver::create(
auto receiver = frpc::HelloWorldReceiver::create(
sub_config,
std::make_shared<CoroHelloWorldReceiver>(),
[](auto error) {
Expand Down
4 changes: 2 additions & 2 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
property:
filename: brpc.hpp
namespace: brpc
filename: frpc.hpp
namespace: frpc

TestType:
type: enum
Expand Down
Loading

0 comments on commit 2a6dfce

Please sign in to comment.