Skip to content

Commit

Permalink
feat: change to grpcbox
Browse files Browse the repository at this point in the history
  • Loading branch information
lsxredrain committed Apr 14, 2023
1 parent dbf1005 commit 47d0046
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 1,137 deletions.
37 changes: 37 additions & 0 deletions apps/dgiot_dlink/priv/example/C#/Dlink/dlink.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ package dgiot;
service Dlink {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}

// If the requested service is unknown, the call will fail with status
// NOT_FOUND.
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);

// Performs a watch for the serving status of the requested service.
// The server will immediately send back a message indicating the current
// serving status. It will then subsequently send a new message whenever
// the service's serving status changes.
//
// If the requested service is unknown when the call is received, the
// server will send a message setting the serving status to
// SERVICE_UNKNOWN but will *not* terminate the call. If at some
// future point, the serving status of the service becomes known, the
// server will send a new message with the service's serving status.
//
// If the call terminates with status UNIMPLEMENTED, then clients
// should assume this method is not supported and should not retry the
// call. If the call terminates with any other status (including OK),
// clients should retry the call with appropriate exponential backoff.
rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse);

}

// The request message containing the user's name.
Expand All @@ -25,3 +47,18 @@ message HelloRequest {
message HelloReply {
string message = 1;
}


message HealthCheckRequest {
string service = 1;
}

message HealthCheckResponse {
enum ServingStatus {
UNKNOWN = 0;
SERVING = 1;
NOT_SERVING = 2;
SERVICE_UNKNOWN = 3; // Used only by the Watch method.
}
ServingStatus status = 1;
}
37 changes: 37 additions & 0 deletions apps/dgiot_dlink/priv/example/java/src/main/proto/dlink.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ package dgiot;
service Dlink {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}

// If the requested service is unknown, the call will fail with status
// NOT_FOUND.
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);

// Performs a watch for the serving status of the requested service.
// The server will immediately send back a message indicating the current
// serving status. It will then subsequently send a new message whenever
// the service's serving status changes.
//
// If the requested service is unknown when the call is received, the
// server will send a message setting the serving status to
// SERVICE_UNKNOWN but will *not* terminate the call. If at some
// future point, the serving status of the service becomes known, the
// server will send a new message with the service's serving status.
//
// If the call terminates with status UNIMPLEMENTED, then clients
// should assume this method is not supported and should not retry the
// call. If the call terminates with any other status (including OK),
// clients should retry the call with appropriate exponential backoff.
rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse);

}

// The request message containing the user's name.
Expand All @@ -25,3 +47,18 @@ message HelloRequest {
message HelloReply {
string message = 1;
}


message HealthCheckRequest {
string service = 1;
}

message HealthCheckResponse {
enum ServingStatus {
UNKNOWN = 0;
SERVING = 1;
NOT_SERVING = 2;
SERVICE_UNKNOWN = 3; // Used only by the Watch method.
}
ServingStatus status = 1;
}
37 changes: 37 additions & 0 deletions apps/dgiot_dlink/priv/protos/dlink.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@ package dgiot;
service Dlink {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}

// If the requested service is unknown, the call will fail with status
// NOT_FOUND.
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);

// Performs a watch for the serving status of the requested service.
// The server will immediately send back a message indicating the current
// serving status. It will then subsequently send a new message whenever
// the service's serving status changes.
//
// If the requested service is unknown when the call is received, the
// server will send a message setting the serving status to
// SERVICE_UNKNOWN but will *not* terminate the call. If at some
// future point, the serving status of the service becomes known, the
// server will send a new message with the service's serving status.
//
// If the call terminates with status UNIMPLEMENTED, then clients
// should assume this method is not supported and should not retry the
// call. If the call terminates with any other status (including OK),
// clients should retry the call with appropriate exponential backoff.
rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse);

}

// The request message containing the user's name.
Expand All @@ -25,3 +47,18 @@ message HelloRequest {
message HelloReply {
string message = 1;
}


message HealthCheckRequest {
string service = 1;
}

message HealthCheckResponse {
enum ServingStatus {
UNKNOWN = 0;
SERVING = 1;
NOT_SERVING = 2;
SERVICE_UNKNOWN = 3; // Used only by the Watch method.
}
ServingStatus status = 1;
}
61 changes: 31 additions & 30 deletions apps/dgiot_dlink/rebar.config
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
%%-*- mode: erlang -*-
{plugins,
[rebar3_proper,
{grpc_plugin, {git, "https://gitee.com/fastdgiot/grpc_plugin.git", {tag, "v0.10.3"}}}
]}.
[rebar3_proper,
{grpc_plugin, {git, "https://gitee.com/fastdgiot/grpc_plugin.git", {tag, "v0.10.3"}}}
]}.

{deps,
[
{grpc, {git, "https://gitee.com/fastdgiot/grpc-erl", {tag, "0.6.7"}}}
[
{grpcbox, {git, "https://gitee.com/fastdgiot/grpcbox", {tag, "v0.16.0"}}}
%% {amqp_client, {git, "https://gitee.com/fastdgiot/amqp_client", {tag, "3.6.2"}}}
]}.
]}.

{grpc,
[
{protos, ["priv/protos"]},
{out_dir, "src/grpc/"},
{gpb_opts, [{module_name_prefix, "dgiot_"},
{module_name_suffix, "_pb"}]}
]}.
[
{type, all},
{protos, ["priv/protos"]},
{out_dir, "src/grpc/"},
{gpb_opts, [{module_name_prefix, "dgiot_"},
{module_name_suffix, "_pb"}]}
]}.

{provider_hooks,
[{pre, [{compile, {grpc, gen}},
{clean, {grpc, clean}}]}
]}.
[{pre, [{compile, {grpc, gen}},
{clean, {grpc, clean}}]}
]}.

{edoc_opts, [{preprocess, true}]}.

{erl_opts, [warn_unused_vars,
warn_shadow_vars,
warn_unused_import,
warn_obsolete_guard,
debug_info,
{parse_transform}]}.
warn_shadow_vars,
warn_unused_import,
warn_obsolete_guard,
debug_info,
{parse_transform}]}.

{xref_checks, [undefined_function_calls, undefined_functions,
locals_not_used, deprecated_function_calls,
warnings_as_errors, deprecated_functions]}.
locals_not_used, deprecated_function_calls,
warnings_as_errors, deprecated_functions]}.
{xref_ignores, [emqx_exhook_pb]}.

{cover_enabled, true}.
{cover_opts, [verbose]}.
{cover_export_enabled, true}.
{cover_excl_mods, [emqx_exhook_pb,
emqx_exhook_v_1_hook_provider_bhvr,
emqx_exhook_v_1_hook_provider_client]}.
emqx_exhook_v_1_hook_provider_bhvr,
emqx_exhook_v_1_hook_provider_client]}.

{profiles,
[{test,
[{deps,
[{emqx_ct_helper, {git, "https://gitee.com/fastdgiot/emqx-ct-helpers", {tag, "v1.3.1"}}}
]}
]}
]}.
[{test,
[{deps,
[{emqx_ct_helper, {git, "https://gitee.com/fastdgiot/emqx-ct-helpers", {tag, "v1.3.1"}}}
]}
]}
]}.
21 changes: 0 additions & 21 deletions apps/dgiot_dlink/src/dgiot_dlink.erl
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,6 @@ send(ClinetId, Map) when is_map(Map) ->
send(_, _) ->
pass.

test() ->
FileName = <<"dlink">>,
Proto = <<"Ly8gY29weSBmcm9tOiBodHRwczovL2dycGMuaW8vZG9jcy93aGF0LWlzLWdycGMvaW50cm9kdWN0aW9uLwoKCnN5bnRheCA9ICJwcm90bzMiOwoKb3B0aW9uIGphdmFfbXVsdGlwbGVfZmlsZXMgPSB0cnVlOwpvcHRpb24gamF2YV9wYWNrYWdlID0gImlvLmdycGMuZXhhbXBsZXMuZGxpbmsiOwpvcHRpb24gamF2YV9vdXRlcl9jbGFzc25hbWUgPSAiRGxpbmtQcm90byI7Cm9wdGlvbiBvYmpjX2NsYXNzX3ByZWZpeCA9ICJkbGluayI7CgpwYWNrYWdlIGRnaW90OwoKLy8gVGhlIGRsaW5rIHNlcnZpY2UgZGVmaW5pdGlvbi4Kc2VydmljZSBEbGluayB7CiAgLy8gU2VuZHMgYSBncmVldGluZwogIHJwYyBTYXlIZWxsbyAoSGVsbG9SZXF1ZXN0KSByZXR1cm5zIChIZWxsb1JlcGx5KSB7fQoKICAvLyBJZiB0aGUgcmVxdWVzdGVkIHNlcnZpY2UgaXMgdW5rbm93biwgdGhlIGNhbGwgd2lsbCBmYWlsIHdpdGggc3RhdHVzCiAgLy8gTk9UX0ZPVU5ELgogIHJwYyBDaGVjayhIZWFsd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xkIG5vdCByZXRyeSB0aGUKICAvLyBjYWxsLiAgSWYgdGhlIGNhbGwgdGVybWluYXRlcyB3aXRoIGFueSBvdGhlciBzdGF0dXMgKGluY2x1ZGluZyBPSyksCiAgLy8gY2xpZW50cyBzaG91bGQgcmV0cnkgdGhlIGNhbGwgd2l0aCBhcHByb3ByaWF0ZSBleHBvbmVudGlhbCBiYWNrb2ZmLgogIHJwYyBXYXRjaChIZWFsdGhDaGVja1JlcXVlc3QpIHJldHVybnMgKHN0cmVhbSBIZWFsdGhDaGVja1Jlc3BvbnNlKTsKCn0KCi8vIFRoZSByZXF1ZXN0IG1lc3NhZ2UgY29udGFpbmluZyB0aGUgdXNlcidzIG5hbWUuCm1lc3NhZ2UgSGVsbG9SZXF1ZXN0IHsKICBzdHJpbmcgbmFtZSA9IDE7Cn0KCi8vIFRoZSByZXNwb25zZSBtZXNzYWdlIGNvbnRhaW5pbmcgdGhlIGdyZWV0aW5ncwptZXNzYWdlIEhlbGxvUmVwbHkgewogIHN0cmluZyBtZXNzYWdlID0gMTsKfQoKCm1lc3NhZ2UgSGVhbHRoQ2hlY2tSZXF1ZXN0IHsKICBzdHJpbmcgc2VydmljZSA9IDE7Cn0KCm1lc3NhZ2UgSGVhbHRoQ2hlY2tSZXNwb25zZSB7CiAgZW51bSBTZXJ2aW5nU3RhdHVzIHsKICAgIFVOS05PV04gPSAwOwogICAgU0VSVklORyA9IDE7CiAgICBOT1RfU0VSVklORyA9IDI7CiAgICBTRVJWSUNFX1VOS05PV04gPSAzOyAgLy8gVXNlZCBvbmx5IGJ5IHRoZSBXYXRjaCBtZXRob2QuCiAgfQogIFNlcnZpbmdTdGF0dXMgc3RhdHVzID0gMTsKfQ==">>,
{file, Here} = code:is_loaded(?MODULE),
ErlangDir = dgiot_httpc:url_join([filename:dirname(filename:dirname(Here)), "/priv/example/Erlang/"]),
Dir = dgiot_httpc:url_join([filename:dirname(filename:dirname(Here)), "/priv/example/Erlang/priv/"]),
Name = dgiot_utils:to_list(FileName),
io:format(" ~s ~p file = ~p ~n", [?FILE, ?LINE, Dir ++ Name ++ ".proto"]),
io:format(" ~s ~p Proto = ~p ~n", [?FILE, ?LINE, base64:decode(Proto)]),
case file:open(Name, [raw, write, delayed_write, binary]) of
{ok, Fd} ->
Result = file:write_file(Dir ++ Name ++ ".proto", base64:decode(Proto)),
file:close(Fd),
io:format(" ~s ~p Result = ~p ~n", [?FILE, ?LINE, Result]);
_ -> pass
end,
Cmd = "cd " ++ ErlangDir ++ " && ./rebar3 compile",
io:format(" ~s ~p Cmd = ~p ~n", [?FILE, ?LINE, Cmd]),
os:cmd(Cmd),
ok.

get_all_protocol() ->
lists:foldl(fun({_, Channel_type}, Acc) ->
App = maps:get(app, Channel_type),
Expand Down
43 changes: 0 additions & 43 deletions apps/dgiot_dlink/src/dgiot_dlink_test.erl

This file was deleted.

13 changes: 0 additions & 13 deletions apps/dgiot_dlink/src/grpc/dgiot_dlink_bhvr.erl

This file was deleted.

45 changes: 0 additions & 45 deletions apps/dgiot_dlink/src/grpc/dgiot_dlink_client.erl

This file was deleted.

Loading

0 comments on commit 47d0046

Please sign in to comment.