{"id":453582,"date":"2025-03-28T09:01:19","date_gmt":"2025-03-28T09:01:19","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=453582"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=453582","title":{"rendered":"<span>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f RPC \u0432\u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0441 Spring Boot<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0441\u0442\u0430\u043b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u043c\u0435\u043b\u043e\u0447\u0438 \u0434\u043b\u044f REST-\u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u044d\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<h4>\u0418 \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u0435\u0441\u043b\u0438:<\/h4>\n<ol>\n<li>\n<p>\u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Java \u0438 Spring Boot \u0432 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u043d\u0430 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0430\u0441 \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 REST-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u0432 \u0438 \u0438\u0445 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443.<\/p>\n<\/li>\n<\/ol>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0448\u0440\u0430\u043c\u044b \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f gRPC, \u0442\u043e \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0434\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043e \u043a\u043e\u043d\u0446\u0430.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u2014 \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u043e\u0435 RPC-\u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430. \u041e\u043d\u043e \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0437\u0430\u043c\u0435\u043d\u0443 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 API, \u043d\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0436\u0438\u0437\u043d\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0433\u0434\u0435 &#171;\u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0433\u0440\u044b&#187; \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0441\u0443\u0434\u0438\u0442\u044c \u0437\u0430 \u043a\u0440\u0443\u0436\u043a\u043e\u0439 \u043f\u0438\u0432\u0430.<\/p>\n<h4>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e?<\/h4>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0423\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434, \u0438\u0437\u0431\u0430\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u043e\u0442 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043e\u0442\u0432\u0435\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u043c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<h4>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 RPC?<\/h4>\n<p><strong>RPC (Remote Procedure Call)<\/strong> \u2014 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u0430 \u0432\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0441\u043a\u0440\u044b\u0442\u0430 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. \u042d\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043a\u043e\u0434 \u0438 \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435, \u0433\u0434\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c.<\/p>\n<h4>\u0427\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c?<\/h4>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 HTTP \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0442\u0435\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0430\u0432\u0442\u043e\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439 \u0434\u043b\u044f Spring Boot \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f RPC \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/h3>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e-\u043c\u0430\u0440\u043a\u0435\u0440 <code>@ModuRpcApi<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432 RPC \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438:<\/p>\n<pre><code class=\"java\">@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface ModuRpcApi { } <\/code><\/pre>\n<p>&#171;\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 <code>ModuRpc<\/code> \u2014 \u044d\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 &#171;Module RPC&#187;, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 ChatGPT.&#187;<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"java\">@ModuRpcApi public interface ClientApi {     String ping(); } <\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u043f\u0440\u0438\u043d\u0433\u043e\u0432\u044b\u0439 \u0431\u0438\u043d:<\/p>\n<pre><code class=\"java\">@Component @Slf4j public class TestRunner implements ApplicationRunner {     private final ClientApi clientApi;      @Autowired     public TestRunner(ClientApi clientApi) {         this.clientApi = clientApi;     }      @Override     public void run(ApplicationArguments args) throws Exception {         String result = clientApi.ping();         log.info(result);     } } <\/code><\/pre>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u2014 \u0438 \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>ClientApi<\/code>. \u041d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u043a\u0441\u0438 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u0432\u044b\u0437\u043e\u0432\u044b RPC.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f RPC-\u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/h3>\n<p><strong>Spring AOP<\/strong> \u0438 <code>MethodInterceptor<\/code> \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u044b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0437\u0430\u0442\u0435\u044e.<\/p>\n<pre><code class=\"java\">public interface MethodInterceptor extends Callback {     \/**      * All generated proxied methods call this method instead of the original method.      * The original method may either be invoked by normal reflection using the Method object,      * or by using the MethodProxy (faster).      * @param obj \"this\", the enhanced object      * @param method intercepted Method      * @param args argument array; primitive types are wrapped      * @param proxy used to invoke super (non-intercepted method); may be called      * as many times as needed      * @throws Throwable any exception may be thrown; if so, super method will not be invoked      * @return any value compatible with the signature of the proxied method. Method returning void will ignore this value.      * @see MethodProxy      *\/     public Object intercept(Object obj, java.lang.reflect.Method method, Object[] args,                                MethodProxy proxy) throws Throwable; } <\/code><\/pre>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a\u0430:<\/p>\n<pre><code class=\"java\">@Component public class ModuRpcClientMethodInterceptor implements MethodInterceptor {     private final HttpClient httpClient;     private final ModuRpcSerializer javaSerializer;      private final ConcurrentMap&lt;Class&lt;?&gt;, String&gt; apiUrls = new ConcurrentHashMap&lt;&gt;();      @Autowired     public ModuRpcClientMethodInterceptor(HttpClient httpClient, ModuRpcSerializer javaSerializer) {         this.httpClient = httpClient;         this.javaSerializer = javaSerializer;     }      @Override     public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {         if (isObjectMethod(method)) {             return handleObjectMethod(obj, method, args);         }          String apiUrl = apiUrls.get(method.getDeclaringClass());         if (apiUrl == null) {             throw new IllegalArgumentException(\"No URL configured for API [%s]\".formatted(method.getDeclaringClass().getName()));         }          String url = \"%s\/rpc\/%s\/%s\".formatted(apiUrl, method.getDeclaringClass().getName(), method.getName());         ModuRpcRequest moduRpcRequest = new ModuRpcRequest(args, method.getParameterTypes());          try {             HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()                     .uri(new URI(url))                     .header(\"Content-Type\", \"application\/octet-stream\")                     .method(\"POST\", HttpRequest.BodyPublishers.ofByteArray(javaSerializer.serialize(moduRpcRequest)));              HttpResponse&lt;byte[]&gt; response = httpClient.send(requestBuilder.build(), HttpResponse.BodyHandlers.ofByteArray());              if (response.statusCode() != 200) {                 throw new ModuRpcTransportException(\"RPC request failed with status: \" + response.statusCode());             }              ModuRpcResponse moduRpcResponse = javaSerializer.deserialize(response.body(), ModuRpcResponse.class);              if (moduRpcResponse == null) {                 throw new ModuRpcTransportException(\"RPC response is null\");             }              if (moduRpcResponse.getResult() instanceof Throwable) {                 throw (Throwable) moduRpcResponse.getResult();             }              if (method.getReturnType().isInstance(moduRpcResponse.getResult())) {                 return method.getReturnType().cast(moduRpcResponse.getResult());             }              return moduRpcResponse.getResult();         } catch (URISyntaxException | IOException | InterruptedException e) {             throw new ModuRpcTransportException(\"RPC transport error: \" + e.getMessage(), e);         }     }      public &lt;T&gt; T createProxy(Class&lt;T&gt; clazz, String url) {         apiUrls.put(clazz, url);          Enhancer enhancer = new Enhancer();         enhancer.setSuperclass(clazz);         enhancer.setCallback(this);         return (T) enhancer.create();     }      private boolean isObjectMethod(Method method) {         return method.getDeclaringClass() == Object.class;     }      private Object handleObjectMethod(Object obj, Method method, Object[] args) {         return switch (method.getName()) {             case \"hashCode\" -&gt; System.identityHashCode(obj);             case \"equals\" -&gt; obj == args[0];             case \"toString\" -&gt; obj.getClass().getName() + \"@\" + Integer.toHexString(System.identityHashCode(obj));             default -&gt; throw new IllegalArgumentException(\"Unexpected method: \" + method);         };     } } <\/code><\/pre>\n<p><strong>\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043a \u043a\u043e\u0434\u0443<\/strong>:<\/p>\n<ul>\n<li>\n<p><code>ConcurrentMap&lt;Class&lt;?&gt;, String&gt; apiUrls<\/code> \u0445\u0440\u0430\u043d\u0438\u0442 URL-\u0430\u0434\u0440\u0435\u0441\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>intercept<\/code> \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0432\u043a\u043b\u044e\u0447\u0430\u044f <code>hashCode<\/code> \u0438 <code>equals<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>createProxy<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u043a\u0441\u0438-\u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f RPC \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/h3>\n<p>\u0414\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438\\\u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/EsotericSoftware\/kryo\" rel=\"noopener noreferrer nofollow\">Kryo<\/a>.<\/p>\n<pre><code class=\"java\">@Component public class KryoModuRpcSerializer implements ModuRpcSerializer {    private static final Logger logger = LoggerFactory.getLogger(KryoModuRpcSerializer.class);     private final Pool&lt;Kryo&gt; kryoPool;     public KryoModuRpcSerializer(Pool&lt;Kryo&gt; kryoPool) {       this.kryoPool = kryoPool;    }     @Override    public byte[] serialize(Object object) {       long startTime = System.nanoTime();       Kryo kryo = kryoPool.obtain();       try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();            Output output = new Output(byteArrayOutputStream)) {          kryo.writeObject(output, object);          output.close();          return byteArrayOutputStream.toByteArray();       } catch (Exception e) {          throw new ModuRpcTransportException(\"Failed to serialize object\", e);       } finally {          kryoPool.free(kryo); \/\/ \u0412\u0435\u0440\u043d\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0432 \u043f\u0443\u043b          long endTime = System.nanoTime();          long durationMicros = TimeUnit.NANOSECONDS.toMicros(endTime - startTime);          logger.debug(\"Serialization time: {} microseconds\", durationMicros);       }    }     @Override    public &lt;T&gt; T deserialize(byte[] data, Class&lt;T&gt; type) {       long startTime = System.nanoTime();       Kryo kryo = kryoPool.obtain();       try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data);            Input input = new Input(byteArrayInputStream)) {          return kryo.readObject(input, type);       } catch (Exception e) {          throw new ModuRpcTransportException(\"Failed to deserialize object\", e);       } finally {          kryoPool.free(kryo); \/\/ \u0412\u0435\u0440\u043d\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0432 \u043f\u0443\u043b          long endTime = System.nanoTime();          long durationMicros = TimeUnit.NANOSECONDS.toMicros(endTime - startTime);          logger.debug(\"Deserialization time: {} microseconds\", durationMicros);       }    } } <\/code><\/pre>\n<p>\u0412\u0430\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c Kryo \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0430\u0432\u0442\u043e\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438\\\u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\">public class KryoPool extends Pool&lt;Kryo&gt; {     public KryoPool(int poolSize) {       super(true, true, poolSize);    }     @Override    protected Kryo create() {       Kryo kryo = new Kryo();       kryo.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));       kryo.setRegistrationRequired(false);       kryo.register(UUID.class, new DefaultSerializers.UUIDSerializer());        kryo.addDefaultSerializer(Throwable.class, new JavaSerializer());       kryo.register(Throwable.class, new JavaSerializer());       return kryo;    } } <\/code><\/pre>\n<p>\u0412 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 Kryo \u0441\u043a\u0430\u0437\u0430\u043d\u043e, \u0447\u0442\u043e \u043e\u043d \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043d\u0435 \u043f\u043e\u0442\u043e\u043a\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439. \u041f\u043e\u0442\u043e\u043c\u0443 \u0435\u0441\u0442\u044c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043f\u0443\u043b\u043e\u0432 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>\u041d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0431\u0438\u043d \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441\u043f\u0440\u0438\u043d\u0433\u0430:<\/p>\n<pre><code class=\"java\">@Bean public ClientApi clientApi(ModuRpcClientMethodInterceptor interceptor) {   return interceptor.createProxy(ClientApi.class, \"http:\/\/localhost:8080\"); } <\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0432\u0441\u0451. \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043b\u044e\u0431\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 RPC-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u043e http.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f RPC-\u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/h3>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 RPC-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 RestController. \u041d\u0443\u0436\u043d\u043e \u0432\u0435\u0441\u0442\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0441\u0435\u0440\u0432\u0435\u0440. \u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440 \u0436\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435.<\/p>\n<pre><code class=\"java\">@RestController @RequestMapping(\"\/rpc\") public class ModuRpcServer {     private final HandlerRegistry handlerRegistry;     private final ModuRpcSerializer javaSerializer;      private static final Logger logger = LoggerFactory.getLogger(ModuRpcServer.class);      @Autowired     public ModuRpcServer(HandlerRegistry handlerRegistry, ModuRpcSerializer javaSerializer) {         this.handlerRegistry = handlerRegistry;         this.javaSerializer = javaSerializer;     }      @PostMapping(\"\/{className}\/{methodName}\")     public byte[] handleRpcRequest(@PathVariable String className, @PathVariable String methodName, @RequestBody byte[] requestBody) throws Throwable {         logger.debug(\"call {}.{} with body length [{}]\", className, methodName, requestBody.length);          try {             Object handler = handlerRegistry.getHandler(className);             if (handler == null) {                 throw new IllegalArgumentException(\"No handler found for api [%s]\".formatted(className));             }              ModuRpcRequest moduRpcRequest = javaSerializer.deserialize(requestBody, ModuRpcRequest.class);             Method method = findMethod(handler.getClass(), methodName, moduRpcRequest.getParameterTypes());             if (method == null) {                 throw new IllegalArgumentException(\"No method found [%s] in class [%s]\".formatted(methodName, className));             }              Object result = method.invoke(handler, moduRpcRequest.getParameters());             return javaSerializer.serialize(new ModuRpcResponse(result));         } catch (InvocationTargetException e) {             return javaSerializer.serialize(new ModuRpcResponse(e.getCause()));         } catch (Throwable e) {             return javaSerializer.serialize(new ModuRpcResponse(e));         }     }      private Method findMethod(Class&lt;?&gt; handlerClass, String methodName, Class&lt;?&gt;[] parameterTypes) {         try {             return handlerClass.getMethod(methodName, parameterTypes);         } catch (NoSuchMethodException e) {             return null;         }     } } <\/code><\/pre>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u2014 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e RPC-\u043a\u043b\u0438\u0435\u043d\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0441 \u0442\u0438\u043f\u0430\u043c\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432:<\/p>\n<pre><code class=\"java\">public class HandlerRegistry {     private final Map&lt;String, Object&gt; handlers = new ConcurrentHashMap&lt;&gt;();      public &lt;T&gt; void registerHandler(Class&lt;T&gt; clazz, Object handler) {         handlers.put(clazz.getName(), handler);     }      public Object getHandler(String className) {         return handlers.get(className);     } } <\/code><\/pre>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e:<\/p>\n<pre><code class=\"java\">@Configuration public class ModuRpcServerConf {     private final HandlerRegistry handlerRegistry;     private final ClientApiHandler clientApiHandler;      public ModuRpcServerConf(HandlerRegistry handlerRegistry, ClientApiHandler clientApiHandler) {         this.handlerRegistry = handlerRegistry;         this.clientApiHandler = clientApiHandler;     }      @PostConstruct     public void registerHandlers() {         handlerRegistry.registerHandler(ClientApi.class, clientApiHandler);     } } <\/code><\/pre>\n<p>\u041d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043a\u043b\u0438\u0435\u043d\u0442 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 RPC \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u0432\u0442\u043e\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439<\/h3>\n<p>\u0421\u0430\u043c\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0437\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0430\u0432\u0442\u043e\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439 (\u043f\u043e \u0441\u0443\u0442\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0441\u043f\u0440\u0438\u043d\u0433\u043e\u0432\u044b\u0439 \u0441\u0442\u0430\u0440\u0442\u0435\u0440), \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c\u0438 \u043d\u0430\u0448\u0438\u0445 \u0442\u0440\u0443\u0434\u043e\u0432.<\/p>\n<h4>\u041a\u043b\u0438\u0435\u043d\u0442<\/h4>\n<p>\u0421 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u043f\u043e\u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c host, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0443\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f RPC-\u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 <code>application.properties<\/code>.<br \/> \u042f \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443:<\/p>\n<pre><code>modurpc.clients.com.example.client.api.url=http:\/\/localhost:8080 modurpc.clients.com.example.payment.api.url=http:\/\/localhost:9090 ... <\/code><\/pre>\n<p>\u0433\u0434\u0435 <code>modurpc.clients.[].url<\/code> &#8212; \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c, \u0430 <code>[]<\/code> &#8212; \u043f\u0430\u043a\u0435\u0442 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043a\u0430\u0442\u044c API \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432 \u0434\u0432\u0443\u0445 \u0440\u0435\u0436\u0438\u043c\u0430\u0445, \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c.<br \/> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c\u0438: <code>\u0441\u0435\u0440\u0432\u0438\u04411<\/code> -&gt; <code>\u0441\u0435\u0440\u0432\u0438\u04412<\/code> -&gt; <code>\u0441\u0435\u0440\u0432\u0438\u04413<\/code>. \u0422\u043e <code>\u0441\u0435\u0440\u0432\u0438\u04412<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c \u0434\u043b\u044f <code>\u0441\u0435\u0440\u0432\u0438\u04411<\/code> \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f <code>\u0441\u0435\u0440\u0432\u0438\u04413<\/code>. \u0410 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<pre><code class=\"java\">public class ModuRpcClientBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor, ApplicationContextAware {    private static final Logger logger = LoggerFactory.getLogger(ModuRpcClientBeanDefinitionRegistryPostProcessor.class);     private final Environment environment;    private ApplicationContext applicationContext;     public ModuRpcClientBeanDefinitionRegistryPostProcessor(Environment environment) {       this.environment = environment;    }     @Override    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {       this.applicationContext = applicationContext;    }     @Override    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {       if (applicationContext != null) {          \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c modurpc.clients          Map&lt;String, String&gt; urlMap = getPropertiesByPattern(\"modurpc.clients\", \".url\");           String basePackage = getBasePackage(applicationContext);          List&lt;String&gt; extraPackages = getExtraScanPackages();           List&lt;String&gt; scanPackages = new ArrayList&lt;&gt;();          if (basePackage != null) {             scanPackages.add(basePackage);          }          scanPackages.addAll(extraPackages);           logger.info(\"Scanning RPC clients in packages: {}\", scanPackages);           Reflections reflections = new Reflections(new ConfigurationBuilder()                  .forPackages(scanPackages.toArray(String[]::new))                  .setScanners(Scanners.TypesAnnotated, Scanners.SubTypes));           Set&lt;Class&lt;?&gt;&gt; rpcApiClasses = reflections.getTypesAnnotatedWith(ModuRpcApi.class);           Set&lt;Class&lt;?&gt;&gt; rpcApiInterfaces = rpcApiClasses.stream()                  .filter(Class::isInterface)                  .collect(Collectors.toSet());           ModuRpcClientMethodInterceptor interceptor = applicationContext.getBean(ModuRpcClientMethodInterceptor.class);           for (Class&lt;?&gt; apiInterface : rpcApiInterfaces) {             if (hasImplementation(registry, apiInterface)) {                continue;             }              if (!urlMap.containsKey(apiInterface.getPackageName())) {                throw new IllegalArgumentException(\"Url for interface [%s] not found. Please set [modurpc.clients.%s.url] in application.properties\"                        .formatted(apiInterface.getName(), apiInterface.getPackageName()));             }              GenericBeanDefinition beanDefinition = new GenericBeanDefinition();             beanDefinition.setBeanClass(ModuRpcClientFactoryBean.class);             beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(apiInterface);             beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(urlMap.get(apiInterface.getPackageName()));             beanDefinition.getConstructorArgumentValues().addGenericArgumentValue(interceptor);              \/\/ \u041f\u043e\u043c\u0435\u0447\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u0447\u0442\u043e \u044d\u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0431\u0438\u043d             beanDefinition.setAttribute(\"modurpc.client\", true);              registry.registerBeanDefinition(apiInterface.getSimpleName(), beanDefinition);             logger.info(\"registered rpc client for [{}]\", apiInterface.getName());          }       }    }     \/\/ \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u0430 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 SpringBootApplication    private String getBasePackage(ApplicationContext context) {       if (context != null) {          for (String beanName : context.getBeanDefinitionNames()) {             Class&lt;?&gt; beanClass = context.getType(beanName);             if (beanClass != null &amp;&amp; beanClass.isAnnotationPresent(SpringBootApplication.class)) {                return beanClass.getPackageName();             }          }       }        logger.warn(\"Cannot determine base package. Please specify 'modurpc.scan.packages' manually.\");       return null;    }     \/\/ \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0434\u043b\u044f \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f    private List&lt;String&gt; getExtraScanPackages() {       String property = environment.getProperty(\"modurpc.scan.packages\");       if (property == null) {          return List.of();       }       return Arrays.stream(property.split(\",\"))               .map(String::trim)               .filter(pkg -&gt; !pkg.isEmpty())               .distinct()               .toList();    }     \/\/ \u0414\u043e\u0431\u044b\u0432\u0430\u0435\u043c \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0439 URL \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430    private Map&lt;String, String&gt; getPropertiesByPattern(String propertyBaseName, String suffix) {       Binder binder = Binder.get(environment);       return binder.bind(propertyBaseName, Bindable.mapOf(String.class, String.class))               .orElse(Collections.emptyMap())               .entrySet()               .stream()               .filter(entry -&gt; entry.getKey().endsWith(suffix))               .collect(Collectors.toMap(                       entry -&gt; entry.getKey().substring(0, entry.getKey().length() - suffix.length()),                       Map.Entry::getValue               ));    }     private boolean hasImplementation(BeanDefinitionRegistry registry, Class&lt;?&gt; apiInterface) {       String[] beanNames = ((ConfigurableListableBeanFactory) registry).getBeanNamesForType(apiInterface);       return beanNames.length &gt; 0;    } } <\/code><\/pre>\n<p>\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043f\u043e \u043a\u043e\u0434\u0443:<\/p>\n<ol>\n<li>\n<p>\u041c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c <code>BeanDefinitionRegistryPostProcessor<\/code> \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u043d \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0431\u0438\u043d\u043e\u0432 \u0435\u0449\u0435 \u043d\u0435\u0442, \u0442\u043e \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 <code>Environment<\/code> \u0437\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043d\u0430\u0448\u0438 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c. \u041b\u043e\u0433\u0438\u0447\u043d\u043e! \u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0433\u0434\u0435 \u0438\u0445 \u0438\u0441\u043a\u0430\u0442\u044c. \u042f \u0440\u0435\u0448\u0438\u043b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 \u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 SpringBootApplication. \u0418 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u044f \u0433\u0434\u0435 \u0438\u0441\u043a\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u043f\u0435\u0440\u0442\u0438 <code>modurpc.scan.packages<\/code>.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e.<\/p>\n<\/li>\n<li>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u0442\u0438\u0442\u044c BeanDefinition, \u0447\u0442\u043e \u044d\u0442\u043e \u043d\u0430\u043c\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0431\u0438\u043d. \u041f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0437\u0436\u0435.<\/p>\n<\/li>\n<\/ol>\n<p>\u041d\u043e \u044d\u0442\u043e\u0433\u043e \u0432\u0441\u0451 \u0435\u0449\u0451 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e. \u041c\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0431\u0438\u043d\u044b, \u043d\u043e \u043e\u043d\u0438 \u043f\u043e\u043a\u0430 \u0431\u0435\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u0432\u043e\u044e \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u0431\u0438\u043d!<\/p>\n<pre><code class=\"java\">public class ModuRpcClientFactoryBean&lt;T&gt; implements FactoryBean&lt;T&gt; {     private final Class&lt;T&gt; apiInterface;     private final String url;     private final ModuRpcClientMethodInterceptor interceptor;      public ModuRpcClientFactoryBean(Class&lt;T&gt; apiInterface, String url, ModuRpcClientMethodInterceptor interceptor) {         this.apiInterface = apiInterface;         this.url = url;         this.interceptor = interceptor;     }      @Override     public T getObject() {         return interceptor.createProxy(apiInterface, url);     }      @Override     public Class&lt;?&gt; getObjectType() {         return apiInterface;     } } <\/code><\/pre>\n<h4>\u0421\u0435\u0440\u0432\u0435\u0440<\/h4>\n<p>\u0422\u0443\u0442, \u043a\u0430\u043a \u0437\u0430\u0432\u0435\u0449\u0430\u043b \u0415\u0432\u0433\u0435\u043d\u0438\u0439 \u0411\u043e\u0440\u0438\u0441\u043e\u0432, \u0441\u0440\u0430\u0437\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <strong>BeanPostProcessor<\/strong>. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043f\u043e\u0438\u0441\u043a \u0432\u0441\u0435\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0431\u0438\u043d, \u0438 \u0435\u0441\u043b\u0438 \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u043d\u0430\u0448\u0438\u043c \u043c\u0430\u0440\u043a\u0435\u0440\u043e\u043c, \u0442\u043e \u044d\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a RPC-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u0435\u0433\u043e \u043d\u0430\u0434\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043d\u0430\u0448\u0435\u043c \u0440\u0435\u0435\u0441\u0442\u0440\u0435.<\/p>\n<pre><code class=\"java\">public class ModuRpcServerBeanPostProcessor implements BeanPostProcessor {     private static final Logger logger = LoggerFactory.getLogger(ModuRpcServerBeanPostProcessor.class);      private final HandlerRegistry handlerRegistry;      public ModuRpcServerBeanPostProcessor(HandlerRegistry handlerRegistry) {         this.handlerRegistry = handlerRegistry;     }      @Override     public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {         Class&lt;?&gt; beanClass = bean.getClass();         for (Class&lt;?&gt; iface : beanClass.getInterfaces()) {             if (iface.isAnnotationPresent(ModuRpcApi.class)) {                 handlerRegistry.registerHandler(iface, bean);                 logger.info(\"Registered RPC handler: {}\", iface.getName());             }         }         return bean;     } } <\/code><\/pre>\n<p>\u041d\u043e \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u043c\u0435\u0442\u0438\u0442, \u0447\u0442\u043e RPC-\u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0442\u043e\u0436\u0435 \u0443\u0436\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e. \u0410 \u0437\u043d\u0430\u0447\u0438\u0442 \u0442\u0430\u043a\u0438\u0435 \u0431\u0438\u043d\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0438 \u043d\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"java\">public class ModuRpcServerBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware {     private static final Logger logger = LoggerFactory.getLogger(ModuRpcServerBeanPostProcessor.class);      private final HandlerRegistry handlerRegistry;     private ApplicationContext applicationContext;      public ModuRpcServerBeanPostProcessor(HandlerRegistry handlerRegistry) {         this.handlerRegistry = handlerRegistry;     }      @Override     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {         this.applicationContext = applicationContext;     }      @Override     public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {         if (bean instanceof FactoryBean) {             return bean; \/\/ \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0444\u0430\u0431\u0440\u0438\u043a\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u043f\u0440\u043e\u043a\u0441\u0438         }          ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) applicationContext;         BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ctx.getBeanFactory();          \/\/ \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0434\u043b\u044f RPC         if (registry.containsBeanDefinition(beanName)) {             BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);             Object isRpcClient = beanDefinition.getAttribute(\"modurpc.client\");             if (Boolean.TRUE.equals(isRpcClient)) {                 return bean;             }         }          \/\/ \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430         Class&lt;?&gt; beanClass = bean.getClass();         for (Class&lt;?&gt; iface : beanClass.getInterfaces()) {             if (iface.isAnnotationPresent(ModuRpcApi.class)) {                 handlerRegistry.registerHandler(iface, bean);                 logger.info(\"Registered RPC handler: {}\", iface.getName());             }         }         return bean;     } } <\/code><\/pre>\n<p>\u0421\u0430\u043c\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043c\u044b \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u043b\u0438. \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e, \u043d\u043e \u044d\u0442\u043e\u0433\u043e \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 (\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445 \u043d\u0430 <a href=\"https:\/\/github.com\/mswindu\/modurpc-example\" rel=\"noopener noreferrer nofollow\">github<\/a>). \u0418 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c maven \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044c \u0432 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0445 \u043d\u0430\u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445.<\/p>\n<h4>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043b, \u043a\u0430\u043a \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u043e\u0435 RPC-\u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u0438\u043b\u0438 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Spring Boot 3.<\/p>\n<p>\u0415\u0449\u0435 \u0440\u0430\u0437 \u043f\u0440\u043e\u043f\u0438\u0448\u0443 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u044d\u0442\u0430\u043f\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438-\u043c\u0430\u0440\u043a\u0435\u0440\u0430 \u0434\u043b\u044f RPC API.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u043a\u0441\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Kryo.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0443 RPC \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Spring RestController.<\/p>\n<\/li>\n<li>\n<p>\u0410\u0432\u0442\u043e\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f RPC \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0432 Spring Boot \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0446\u0435\u043b\u044c \u2014 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438, \u0441\u0434\u0435\u043b\u0430\u0432 \u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u044b\u043c \u0438 \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430 \u0432\u044b\u0437\u043e\u0432 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435, \u0433\u0434\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043e. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u0432, \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u0438\u043b\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u0430\u0436\u0435 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0432\u0438\u0434\u0435 \u044d\u0442\u043e\u0442 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 \u0430\u0440\u0441\u0435\u043d\u0430\u043b\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432.<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0438 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0438\u0442 \u0432\u0430\u0441 \u043d\u0430 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b \u0441 RPC \u0438 Spring Boot. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044e, \u043d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u043c\u0438 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. \u0423\u0434\u0430\u0447\u0438 \u0432 \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445!<\/p>\n<p>\u0418\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043d\u0430 <a href=\"https:\/\/github.com\/mswindu\/modurpc-example\" rel=\"noopener noreferrer nofollow\">github<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/895172\/\"> https:\/\/habr.com\/ru\/articles\/895172\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0441\u0442\u0430\u043b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u044d\u0442\u0438 \u043c\u0435\u043b\u043e\u0447\u0438 \u0434\u043b\u044f REST-\u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u0430\u0445, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u044d\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u0443.<\/p>\n<h4>\u0418 \u044f \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0432\u0430\u043c \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e, \u0435\u0441\u043b\u0438:<\/h4>\n<ol>\n<li>\n<p>\u0412\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 Java \u0438 Spring Boot \u0432 \u0441\u0432\u043e\u0435\u0439 \u0440\u0430\u0431\u043e\u0442\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0430\u0448 \u043f\u0440\u043e\u0435\u043a\u0442 \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u043d\u0430 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0430\u0441 \u0440\u0430\u0437\u0434\u0440\u0430\u0436\u0430\u0435\u0442 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 REST-\u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u043e\u0432 \u0438 \u0438\u0445 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443.<\/p>\n<\/li>\n<\/ol>\n<p>\u0410 \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0448\u0440\u0430\u043c\u044b \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u043e\u043a \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f gRPC, \u0442\u043e \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u0434\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0434\u043e \u043a\u043e\u043d\u0446\u0430.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u2014 \u043b\u0435\u0433\u043a\u043e\u0432\u0435\u0441\u043d\u043e\u0435 RPC-\u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u0430. \u041e\u043d\u043e \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0437\u0430\u043c\u0435\u043d\u0443 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 API, \u043d\u043e \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u0436\u0438\u0437\u043d\u044c \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0433\u0434\u0435 &#171;\u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438\u0433\u0440\u044b&#187; \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0441\u0443\u0434\u0438\u0442\u044c \u0437\u0430 \u043a\u0440\u0443\u0436\u043a\u043e\u0439 \u043f\u0438\u0432\u0430.<\/p>\n<h4>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e?<\/h4>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0423\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434, \u0438\u0437\u0431\u0430\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u043e\u0442 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u043e\u0442\u0432\u0435\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0441\u0435\u0440\u0432\u0438\u0441\u0430\u043c\u0438 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043f\u043e\u0445\u043e\u0436\u0438\u043c \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u043c.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0442\u0430\u043a, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<h4>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 RPC?<\/h4>\n<p><strong>RPC (Remote Procedure Call)<\/strong> \u2014 \u044d\u0442\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u043e\u043c \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0442\u0430\u043a, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u043e\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u043f\u0430\u0440\u0441\u0438\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u0430 \u0432\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0443\u0434\u0430\u043b\u0435\u043d\u043d\u044b\u043c \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c \u0441\u043a\u0440\u044b\u0442\u0430 \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. \u042d\u0442\u043e \u0443\u043f\u0440\u043e\u0449\u0430\u0435\u0442 \u043a\u043e\u0434 \u0438 \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432 \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u043d\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435, \u0433\u0434\u0435 \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c.<\/p>\n<h4>\u0427\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c?<\/h4>\n<ol>\n<li>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 HTTP \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0442\u0435\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438 \u043e\u0442\u0432\u0435\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0430\u0432\u0442\u043e\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0439 \u0434\u043b\u044f Spring Boot \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<\/li>\n<\/ol>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f RPC \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/h3>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0448\u0430\u0433\u043e\u043c \u044f \u0441\u043e\u0437\u0434\u0430\u043b \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e-\u043c\u0430\u0440\u043a\u0435\u0440 <code>@ModuRpcApi<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043c\u0435\u0447\u0430\u0442\u044c \u0432\u0441\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0443\u0447\u0430\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0432 RPC \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0438:<\/p>\n<pre><code class=\"java\">@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface ModuRpcApi { } <\/code><\/pre>\n<p>&#171;\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 <code>ModuRpc<\/code> \u2014 \u044d\u0442\u043e \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u043e\u0442 &#171;Module RPC&#187;, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0435 ChatGPT.&#187;<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<pre><code class=\"java\">@ModuRpcApi public interface ClientApi {     String ping(); } <\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0441\u043f\u0440\u0438\u043d\u0433\u043e\u0432\u044b\u0439 \u0431\u0438\u043d:<\/p>\n<pre><code class=\"java\">@Component @Slf4j public class TestRunner implements ApplicationRunner {     private final ClientApi clientApi;      @Autowired     public TestRunner(ClientApi clientApi) {         this.clientApi = clientApi;     }      @Override     public void run(ApplicationArguments args) throws Exception {         String result = clientApi.ping();         log.info(result);     } } <\/code><\/pre>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u2014 \u0438 \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>ClientApi<\/code>. \u041d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u043a\u0441\u0438 \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u0432\u044b\u0437\u043e\u0432\u044b RPC.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f RPC-\u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/h3>\n<p><strong>Spring AOP<\/strong> \u0438 <code>MethodInterceptor<\/code> \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u044b \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0437\u0430\u0442\u0435\u044e.<\/p>\n<pre><code class=\"java\">public interface MethodInterceptor extends Callback {     \/**      * All generated proxied methods call this method instead of the original method.      * The original method may either be invoked by normal reflection using the Method object,      * or by using the MethodProxy (faster).      * @param obj \"this\", the enhanced object      * @param method intercepted Method      * @param args argument array; primitive types are wrapped      * @param proxy used to invoke super (non-intercepted method); may be called      * as many times as needed      * @throws Throwable any exception may be thrown; if so, super method will not be invoked      * @return any value compatible with the signature of the proxied method. Method returning void will ignore this value.      * @see MethodProxy      *\/     public Object intercept(Object obj, java.lang.reflect.Method method, Object[] args,                                MethodProxy proxy) throws Throwable; } <\/code><\/pre>\n<p>\u041d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a\u0430:<\/p>\n<pre><code class=\"java\">@Component public class ModuRpcClientMethodInterceptor implements MethodInterceptor {     private final HttpClient httpClient;     private final ModuRpcSerializer javaSerializer;      private final ConcurrentMap&lt;Class&lt;?&gt;, String&gt; apiUrls = new ConcurrentHashMap&lt;&gt;();      @Autowired     public ModuRpcClientMethodInterceptor(HttpClient httpClient, ModuRpcSerializer javaSerializer) {         this.httpClient = httpClient;         this.javaSerializer = javaSerializer;     }      @Override     public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {         if (isObjectMethod(method)) {             return handleObjectMethod(obj, method, args);         }          String apiUrl = apiUrls.get(method.getDeclaringClass());         if (apiUrl == null) {             throw new IllegalArgumentException(\"No URL configured for API [%s]\".formatted(method.getDeclaringClass().getName()));         }          String url = \"%s\/rpc\/%s\/%s\".formatted(apiUrl, method.getDeclaringClass().getName(), method.getName());         ModuRpcRequest moduRpcRequest = new ModuRpcRequest(args, method.getParameterTypes());          try {             HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()                     .uri(new URI(url))                     .header(\"Content-Type\", \"application\/octet-stream\")                     .method(\"POST\", HttpRequest.BodyPublishers.ofByteArray(javaSerializer.serialize(moduRpcRequest)));              HttpResponse&lt;byte[]&gt; response = httpClient.send(requestBuilder.build(), HttpResponse.BodyHandlers.ofByteArray());              if (response.statusCode() != 200) {                 throw new ModuRpcTransportException(\"RPC request failed with status: \" + response.statusCode());             }              ModuRpcResponse moduRpcResponse = javaSerializer.deserialize(response.body(), ModuRpcResponse.class);              if (moduRpcResponse == null) {                 throw new ModuRpcTransportException(\"RPC response is null\");             }              if (moduRpcResponse.getResult() instanceof Throwable) {                 throw (Throwable) moduRpcResponse.getResult();             }              if (method.getReturnType().isInstance(moduRpcResponse.getResult())) {                 return method.getReturnType().cast(moduRpcResponse.getResult());             }              return moduRpcResponse.getResult();         } catch (URISyntaxException | IOException | InterruptedException e) {             throw new ModuRpcTransportException(\"RPC transport error: \" + e.getMessage(), e);         }     }      public &lt;T&gt; T createProxy(Class&lt;T&gt; clazz, String url) {         apiUrls.put(clazz, url);          Enhancer enhancer = new Enhancer();         enhancer.setSuperclass(clazz);         enhancer.setCallback(this);         return (T) enhancer.create();     }      private boolean isObjectMethod(Method method) {         return method.getDeclaringClass() == Object.class;     }      private Object handleObjectMethod(Object obj, Method method, Object[] args) {         return switch (method.getName()) {             case \"hashCode\" -&gt; System.identityHashCode(obj);             case \"equals\" -&gt; obj == args[0];             case \"toString\" -&gt; obj.getClass().getName() + \"@\" + Integer.toHexString(System.identityHashCode(obj));             default -&gt; throw new IllegalArgumentException(\"Unexpected method: \" + method);         };     } } <\/code><\/pre>\n<p><strong>\u041a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043a \u043a\u043e\u0434\u0443<\/strong>:<\/p>\n<ul>\n<li>\n<p><code>ConcurrentMap&lt;Class&lt;?&gt;, String&gt; apiUrls<\/code> \u0445\u0440\u0430\u043d\u0438\u0442 URL-\u0430\u0434\u0440\u0435\u0441\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>intercept<\/code> \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0432\u043a\u043b\u044e\u0447\u0430\u044f <code>hashCode<\/code> \u0438 <code>equals<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>createProxy<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u043a\u0441\u0438-\u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f RPC \u043a\u043b\u0438\u0435\u043d\u0442\u0430.<\/p>\n<\/li>\n<\/ul>\n<h3>\u0421\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/h3>\n<p>\u0414\u043b\u044f \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438\\\u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0435\u0448\u0438\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/EsotericSoftware\/kryo\" rel=\"noopener noreferrer nofollow\">Kryo<\/a>.<\/p>\n<pre><code class=\"java\">@Component public class KryoModuRpcSerializer implements ModuRpcSerializer {    private static final Logger logger = LoggerFactory.getLogger(KryoModuRpcSerializer.class);     private final Pool&lt;Kryo&gt; kryoPool;     public KryoModuRpcSerializer(Pool&lt;Kryo&gt; kryoPool) {       this.kryoPool = kryoPool;    }     @Override    public byte[] serialize(Object object) {       long startTime = System.nanoTime();       Kryo kryo = kryoPool.obtain();       try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();            Output output = new Output(byteArrayOutputStream)) {          kryo.writeObject(output, object);          output.close();          return byteArrayOutputStream.toByteArray();       } catch (Exception e) {          throw new ModuRpcTransportException(\"Failed to serialize object\", e);       } finally {          kryoPool.free(kryo); \/\/ \u0412\u0435\u0440\u043d\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0432 \u043f\u0443\u043b          long endTime = System.nanoTime();          long durationMicros = TimeUnit.NANOSECONDS.toMicros(endTime - startTime);          logger.debug(\"Serialization time: {} microseconds\", durationMicros);       }    }     @Override    public &lt;T&gt; T deserialize(byte[] data, Class&lt;T&gt; type) {       long startTime = System.nanoTime();       Kryo kryo = kryoPool.obtain();       try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data);            Input input = new Input(byteArrayInputStream)) {          return kryo.readObject(input, type);       } catch (Exception e) {          throw new ModuRpcTransportException(\"Failed to deserialize object\", e);       } finally {          kryoPool.free(kryo); \/\/ \u0412\u0435\u0440\u043d\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0432 \u043f\u0443\u043b          long endTime = System.nanoTime();          long durationMicros = TimeUnit.NANOSECONDS.toMicros(endTime - startTime);          logger.debug(\"Deserialization time: {} microseconds\", durationMicros);       }    } } <\/code><\/pre>\n<p>\u0412\u0430\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c Kryo \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0430\u0432\u0442\u043e\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0435\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438\\\u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"java\">public class KryoPool extends Pool&lt;Kryo&gt; {     public KryoPool(int poolSize) {       super(true, true, poolSize);    }     @Override    protected Kryo create() {       Kryo kryo = new Kryo();       kryo.setInstantiatorStrategy(new<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-453582","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/453582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=453582"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/453582\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=453582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=453582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=453582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}