diff options
author | nga <nga@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
commit | 1f553f46fb4f3c5eec631352cdd900a0709016af (patch) | |
tree | a231fba2c03b440becaea6c86a2702d0bfb0336e /library/cpp/messagebus/test/example | |
parent | c4de7efdedc25b49cbea74bd589eecb61b55b60a (diff) | |
download | ydb-1f553f46fb4f3c5eec631352cdd900a0709016af.tar.gz |
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/messagebus/test/example')
-rw-r--r-- | library/cpp/messagebus/test/example/client/client.cpp | 146 | ||||
-rw-r--r-- | library/cpp/messagebus/test/example/client/ya.make | 22 | ||||
-rw-r--r-- | library/cpp/messagebus/test/example/common/messages.proto | 30 | ||||
-rw-r--r-- | library/cpp/messagebus/test/example/common/proto.cpp | 24 | ||||
-rw-r--r-- | library/cpp/messagebus/test/example/common/proto.h | 24 | ||||
-rw-r--r-- | library/cpp/messagebus/test/example/common/ya.make | 24 | ||||
-rw-r--r-- | library/cpp/messagebus/test/example/server/server.cpp | 104 | ||||
-rw-r--r-- | library/cpp/messagebus/test/example/server/ya.make | 22 | ||||
-rw-r--r-- | library/cpp/messagebus/test/example/ya.make | 6 |
9 files changed, 201 insertions, 201 deletions
diff --git a/library/cpp/messagebus/test/example/client/client.cpp b/library/cpp/messagebus/test/example/client/client.cpp index 89b5f2c9be..3bd9a6f768 100644 --- a/library/cpp/messagebus/test/example/client/client.cpp +++ b/library/cpp/messagebus/test/example/client/client.cpp @@ -1,81 +1,81 @@ #include <library/cpp/messagebus/test/example/common/proto.h> -#include <util/random/random.h> - -using namespace NBus; -using namespace NCalculator; - -namespace NCalculator { +#include <util/random/random.h> + +using namespace NBus; +using namespace NCalculator; + +namespace NCalculator { struct TCalculatorClient: public IBusClientHandler { - TCalculatorProtocol Proto; - TBusMessageQueuePtr MessageQueue; - TBusClientSessionPtr ClientSession; - - TCalculatorClient() { - MessageQueue = CreateMessageQueue(); - TBusClientSessionConfig config; - config.TotalTimeout = 2 * 1000; - ClientSession = TBusClientSession::Create(&Proto, this, config, MessageQueue); - } - + TCalculatorProtocol Proto; + TBusMessageQueuePtr MessageQueue; + TBusClientSessionPtr ClientSession; + + TCalculatorClient() { + MessageQueue = CreateMessageQueue(); + TBusClientSessionConfig config; + config.TotalTimeout = 2 * 1000; + ClientSession = TBusClientSession::Create(&Proto, this, config, MessageQueue); + } + ~TCalculatorClient() override { - MessageQueue->Stop(); - } - + MessageQueue->Stop(); + } + void OnReply(TAutoPtr<TBusMessage> request, TAutoPtr<TBusMessage> response0) override { Y_VERIFY(response0->GetHeader()->Type == TResponse::MessageType, "wrong response"); - TResponse* response = VerifyDynamicCast<TResponse*>(response0.Get()); - if (request->GetHeader()->Type == TRequestSum::MessageType) { - TRequestSum* requestSum = VerifyDynamicCast<TRequestSum*>(request.Get()); - int a = requestSum->Record.GetA(); - int b = requestSum->Record.GetB(); - Cerr << a << " + " << b << " = " << response->Record.GetResult() << "\n"; - } else if (request->GetHeader()->Type == TRequestMul::MessageType) { - TRequestMul* requestMul = VerifyDynamicCast<TRequestMul*>(request.Get()); - int a = requestMul->Record.GetA(); - int b = requestMul->Record.GetB(); - Cerr << a << " * " << b << " = " << response->Record.GetResult() << "\n"; - } else { + TResponse* response = VerifyDynamicCast<TResponse*>(response0.Get()); + if (request->GetHeader()->Type == TRequestSum::MessageType) { + TRequestSum* requestSum = VerifyDynamicCast<TRequestSum*>(request.Get()); + int a = requestSum->Record.GetA(); + int b = requestSum->Record.GetB(); + Cerr << a << " + " << b << " = " << response->Record.GetResult() << "\n"; + } else if (request->GetHeader()->Type == TRequestMul::MessageType) { + TRequestMul* requestMul = VerifyDynamicCast<TRequestMul*>(request.Get()); + int a = requestMul->Record.GetA(); + int b = requestMul->Record.GetB(); + Cerr << a << " * " << b << " = " << response->Record.GetResult() << "\n"; + } else { Y_FAIL("unknown request"); - } - } - + } + } + void OnError(TAutoPtr<TBusMessage>, EMessageStatus status) override { - Cerr << "got error " << status << "\n"; - } - }; - -} - -int main(int, char**) { - TCalculatorClient client; - - for (;;) { - TNetAddr addr(TNetAddr("127.0.0.1", TCalculatorProtocol().GetPort())); - - int a = RandomNumber<unsigned>(10); - int b = RandomNumber<unsigned>(10); - EMessageStatus ok; - if (RandomNumber<bool>()) { - TAutoPtr<TRequestSum> request(new TRequestSum); - request->Record.SetA(a); - request->Record.SetB(b); - Cerr << "sending " << a << " + " << b << "\n"; - ok = client.ClientSession->SendMessageAutoPtr(request, &addr); - } else { - TAutoPtr<TRequestMul> request(new TRequestMul); - request->Record.SetA(a); - request->Record.SetB(b); - Cerr << "sending " << a << " * " << b << "\n"; - ok = client.ClientSession->SendMessageAutoPtr(request, &addr); - } - - if (ok != MESSAGE_OK) { - Cerr << "failed to send message " << ok << "\n"; - } - - Sleep(TDuration::Seconds(1)); - } - - return 0; -} + Cerr << "got error " << status << "\n"; + } + }; + +} + +int main(int, char**) { + TCalculatorClient client; + + for (;;) { + TNetAddr addr(TNetAddr("127.0.0.1", TCalculatorProtocol().GetPort())); + + int a = RandomNumber<unsigned>(10); + int b = RandomNumber<unsigned>(10); + EMessageStatus ok; + if (RandomNumber<bool>()) { + TAutoPtr<TRequestSum> request(new TRequestSum); + request->Record.SetA(a); + request->Record.SetB(b); + Cerr << "sending " << a << " + " << b << "\n"; + ok = client.ClientSession->SendMessageAutoPtr(request, &addr); + } else { + TAutoPtr<TRequestMul> request(new TRequestMul); + request->Record.SetA(a); + request->Record.SetB(b); + Cerr << "sending " << a << " * " << b << "\n"; + ok = client.ClientSession->SendMessageAutoPtr(request, &addr); + } + + if (ok != MESSAGE_OK) { + Cerr << "failed to send message " << ok << "\n"; + } + + Sleep(TDuration::Seconds(1)); + } + + return 0; +} diff --git a/library/cpp/messagebus/test/example/client/ya.make b/library/cpp/messagebus/test/example/client/ya.make index a660a01698..81713a5318 100644 --- a/library/cpp/messagebus/test/example/client/ya.make +++ b/library/cpp/messagebus/test/example/client/ya.make @@ -1,13 +1,13 @@ -PROGRAM(messagebus_example_client) - +PROGRAM(messagebus_example_client) + OWNER(g:messagebus) - -PEERDIR( + +PEERDIR( library/cpp/messagebus/test/example/common -) - -SRCS( - client.cpp -) - -END() +) + +SRCS( + client.cpp +) + +END() diff --git a/library/cpp/messagebus/test/example/common/messages.proto b/library/cpp/messagebus/test/example/common/messages.proto index 16b858fc77..12cdf38fb5 100644 --- a/library/cpp/messagebus/test/example/common/messages.proto +++ b/library/cpp/messagebus/test/example/common/messages.proto @@ -1,15 +1,15 @@ -package NCalculator; - -message TRequestSumRecord { - required int32 A = 1; - required int32 B = 2; -} - -message TRequestMulRecord { - required int32 A = 1; - required int32 B = 2; -} - -message TResponseRecord { - required int32 Result = 1; -} +package NCalculator; + +message TRequestSumRecord { + required int32 A = 1; + required int32 B = 2; +} + +message TRequestMulRecord { + required int32 A = 1; + required int32 B = 2; +} + +message TResponseRecord { + required int32 Result = 1; +} diff --git a/library/cpp/messagebus/test/example/common/proto.cpp b/library/cpp/messagebus/test/example/common/proto.cpp index 1d18aa77ea..3531e3d06c 100644 --- a/library/cpp/messagebus/test/example/common/proto.cpp +++ b/library/cpp/messagebus/test/example/common/proto.cpp @@ -1,12 +1,12 @@ -#include "proto.h" - -using namespace NCalculator; -using namespace NBus; - -TCalculatorProtocol::TCalculatorProtocol() - : TBusBufferProtocol("Calculator", 34567) -{ - RegisterType(new TRequestSum); - RegisterType(new TRequestMul); - RegisterType(new TResponse); -} +#include "proto.h" + +using namespace NCalculator; +using namespace NBus; + +TCalculatorProtocol::TCalculatorProtocol() + : TBusBufferProtocol("Calculator", 34567) +{ + RegisterType(new TRequestSum); + RegisterType(new TRequestMul); + RegisterType(new TResponse); +} diff --git a/library/cpp/messagebus/test/example/common/proto.h b/library/cpp/messagebus/test/example/common/proto.h index a151aac468..f9fbd5ce56 100644 --- a/library/cpp/messagebus/test/example/common/proto.h +++ b/library/cpp/messagebus/test/example/common/proto.h @@ -1,17 +1,17 @@ -#pragma once - +#pragma once + #include <library/cpp/messagebus/test/example/common/messages.pb.h> - + #include <library/cpp/messagebus/ybus.h> #include <library/cpp/messagebus/protobuf/ybusbuf.h> -namespace NCalculator { - typedef ::NBus::TBusBufferMessage<TRequestSumRecord, 1> TRequestSum; - typedef ::NBus::TBusBufferMessage<TRequestMulRecord, 2> TRequestMul; - typedef ::NBus::TBusBufferMessage<TResponseRecord, 3> TResponse; - +namespace NCalculator { + typedef ::NBus::TBusBufferMessage<TRequestSumRecord, 1> TRequestSum; + typedef ::NBus::TBusBufferMessage<TRequestMulRecord, 2> TRequestMul; + typedef ::NBus::TBusBufferMessage<TResponseRecord, 3> TResponse; + struct TCalculatorProtocol: public ::NBus::TBusBufferProtocol { - TCalculatorProtocol(); - }; - -} + TCalculatorProtocol(); + }; + +} diff --git a/library/cpp/messagebus/test/example/common/ya.make b/library/cpp/messagebus/test/example/common/ya.make index 4da16608fc..14f48ff6c0 100644 --- a/library/cpp/messagebus/test/example/common/ya.make +++ b/library/cpp/messagebus/test/example/common/ya.make @@ -1,15 +1,15 @@ -LIBRARY(messagebus_test_example_common) - +LIBRARY(messagebus_test_example_common) + OWNER(g:messagebus) - -PEERDIR( + +PEERDIR( library/cpp/messagebus library/cpp/messagebus/protobuf -) - -SRCS( - proto.cpp - messages.proto -) - -END() +) + +SRCS( + proto.cpp + messages.proto +) + +END() diff --git a/library/cpp/messagebus/test/example/server/server.cpp b/library/cpp/messagebus/test/example/server/server.cpp index 13e52d75f5..a080f3548b 100644 --- a/library/cpp/messagebus/test/example/server/server.cpp +++ b/library/cpp/messagebus/test/example/server/server.cpp @@ -1,58 +1,58 @@ #include <library/cpp/messagebus/test/example/common/proto.h> - -using namespace NBus; -using namespace NCalculator; - -namespace NCalculator { + +using namespace NBus; +using namespace NCalculator; + +namespace NCalculator { struct TCalculatorServer: public IBusServerHandler { - TCalculatorProtocol Proto; - TBusMessageQueuePtr MessageQueue; - TBusServerSessionPtr ServerSession; - - TCalculatorServer() { - MessageQueue = CreateMessageQueue(); - TBusServerSessionConfig config; - ServerSession = TBusServerSession::Create(&Proto, this, config, MessageQueue); - } - + TCalculatorProtocol Proto; + TBusMessageQueuePtr MessageQueue; + TBusServerSessionPtr ServerSession; + + TCalculatorServer() { + MessageQueue = CreateMessageQueue(); + TBusServerSessionConfig config; + ServerSession = TBusServerSession::Create(&Proto, this, config, MessageQueue); + } + ~TCalculatorServer() override { - MessageQueue->Stop(); - } - + MessageQueue->Stop(); + } + void OnMessage(TOnMessageContext& request) override { - if (request.GetMessage()->GetHeader()->Type == TRequestSum::MessageType) { - TRequestSum* requestSum = VerifyDynamicCast<TRequestSum*>(request.GetMessage()); - int a = requestSum->Record.GetA(); - int b = requestSum->Record.GetB(); - int result = a + b; - Cerr << "requested " << a << " + " << b << ", sending " << result << "\n"; - TAutoPtr<TResponse> response(new TResponse); - response->Record.SetResult(result); - request.SendReplyMove(response); - } else if (request.GetMessage()->GetHeader()->Type == TRequestMul::MessageType) { - TRequestMul* requestMul = VerifyDynamicCast<TRequestMul*>(request.GetMessage()); - int a = requestMul->Record.GetA(); - int b = requestMul->Record.GetB(); - int result = a * b; - Cerr << "requested " << a << " * " << b << ", sending " << result << "\n"; - TAutoPtr<TResponse> response(new TResponse); - response->Record.SetResult(result); - request.SendReplyMove(response); - } else { + if (request.GetMessage()->GetHeader()->Type == TRequestSum::MessageType) { + TRequestSum* requestSum = VerifyDynamicCast<TRequestSum*>(request.GetMessage()); + int a = requestSum->Record.GetA(); + int b = requestSum->Record.GetB(); + int result = a + b; + Cerr << "requested " << a << " + " << b << ", sending " << result << "\n"; + TAutoPtr<TResponse> response(new TResponse); + response->Record.SetResult(result); + request.SendReplyMove(response); + } else if (request.GetMessage()->GetHeader()->Type == TRequestMul::MessageType) { + TRequestMul* requestMul = VerifyDynamicCast<TRequestMul*>(request.GetMessage()); + int a = requestMul->Record.GetA(); + int b = requestMul->Record.GetB(); + int result = a * b; + Cerr << "requested " << a << " * " << b << ", sending " << result << "\n"; + TAutoPtr<TResponse> response(new TResponse); + response->Record.SetResult(result); + request.SendReplyMove(response); + } else { Y_FAIL("unknown request"); - } - } - }; -} - -int main(int, char**) { - TCalculatorServer server; - - Cerr << "listening on port " << server.ServerSession->GetActualListenPort() << "\n"; - - for (;;) { - Sleep(TDuration::Seconds(1)); - } - - return 0; + } + } + }; } + +int main(int, char**) { + TCalculatorServer server; + + Cerr << "listening on port " << server.ServerSession->GetActualListenPort() << "\n"; + + for (;;) { + Sleep(TDuration::Seconds(1)); + } + + return 0; +} diff --git a/library/cpp/messagebus/test/example/server/ya.make b/library/cpp/messagebus/test/example/server/ya.make index 8cdd97cb12..3bf4c31853 100644 --- a/library/cpp/messagebus/test/example/server/ya.make +++ b/library/cpp/messagebus/test/example/server/ya.make @@ -1,13 +1,13 @@ -PROGRAM(messagebus_example_server) - +PROGRAM(messagebus_example_server) + OWNER(g:messagebus) - -PEERDIR( + +PEERDIR( library/cpp/messagebus/test/example/common -) - -SRCS( - server.cpp -) - -END() +) + +SRCS( + server.cpp +) + +END() diff --git a/library/cpp/messagebus/test/example/ya.make b/library/cpp/messagebus/test/example/ya.make index f275351c29..972458d255 100644 --- a/library/cpp/messagebus/test/example/ya.make +++ b/library/cpp/messagebus/test/example/ya.make @@ -1,7 +1,7 @@ OWNER(g:messagebus) - -RECURSE( + +RECURSE( client common server -) +) |