This is an automated email from the ASF dual-hosted git repository.

github-bot pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/dubbo-website.git


The following commit(s) were added to refs/heads/asf-site by this push:
     new 698ed48  Automated deployment: Fri Nov  8 05:12:52 UTC 2019 
7877c75f07390d543693b51c120ccb3795da81d9
698ed48 is described below

commit 698ed48d5594049e41b4030c98c1ea19803d7b37
Author: lexburner <[email protected]>
AuthorDate: Fri Nov 8 05:12:52 2019 +0000

    Automated deployment: Fri Nov  8 05:12:52 UTC 2019 
7877c75f07390d543693b51c120ccb3795da81d9
---
 md_json/docs.json                                  |   5 +
 .../user/demos/GooglePb-generic-reference.html     | 106 +++++++++++++++++++++
 .../user/demos/GooglePb-generic-reference.json     |   6 ++
 3 files changed, 117 insertions(+)

diff --git a/md_json/docs.json b/md_json/docs.json
index ba40b8b..1cb3865 100644
--- a/md_json/docs.json
+++ b/md_json/docs.json
@@ -1594,6 +1594,11 @@
       "meta": {}
     },
     {
+      "filename": "GooglePb-generic-reference.md",
+      "link": "/zh-cn/docs/user/demos/GooglePb-generic-reference.html",
+      "meta": {}
+    },
+    {
       "filename": "accesslog.md",
       "link": "/zh-cn/docs/user/demos/accesslog.html",
       "meta": {}
diff --git a/zh-cn/docs/user/demos/GooglePb-generic-reference.html 
b/zh-cn/docs/user/demos/GooglePb-generic-reference.html
new file mode 100644
index 0000000..e7a82e8
--- /dev/null
+++ b/zh-cn/docs/user/demos/GooglePb-generic-reference.html
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+       <meta charset="UTF-8">
+       <meta name="viewport" content="width=device-width, initial-scale=1.0, 
maximum-scale=1.0, user-scalable=no">
+       <meta name="keywords" content="GooglePb-generic-reference" />
+       <meta name="description" content="GooglePb-generic-reference" />
+       <!-- 网页标签标题 -->
+       <title>GooglePb-generic-reference</title>
+       <link rel="shortcut icon" href="/img/dubbo.ico"/>
+       <link rel="stylesheet" href="/build/documentation.css" />
+</head>
+<body>
+       <div id="root"><div class="documentation-page" 
data-reactroot=""><header class="header-container header-container-normal"><div 
class="header-body"><a href="/zh-cn/index.html"><img class="logo" 
src="/img/dubbo_colorful.png"/></a><div class="search search-normal"><span 
class="icon-search"></span></div><span class="language-switch 
language-switch-normal">En</span><div class="header-menu"><img 
class="header-menu-toggle" src="/img/menu_gray.png"/><ul><li class="menu-item 
menu-item-normal"><a [...]
+<p>泛化接口调用方式主要用于客户端没有 API 接口及模型类元的情况,参考 <a 
href="http://dubbo.apache.org/zh-cn/docs/user/demos/group-merger.html";>泛化调用</a>。
+一般泛化调用只能用于生成的服务参数为POJO的情况,而GoogleProtobuf的对象是基于Builder生成的非正常POJO,可以通过protobuf-json泛化调用。<br>
+GoogleProtobuf序列化相关的Demo可以参考<a 
href="https://github.com/vio-lin/dubbo-samples/tree/protobuf-demo";>protobuf-demo</a></p>
+<h1>通过Spring对Goolgle Protobuf对象泛化调用</h1>
+<p>在Spring中配置声明generic = &quot;protobuf-json&quot;</p>
+<pre><code>&lt;dubbo:reference id=&quot;barService&quot; 
interface=&quot;com.foo.BarService&quot; generic=&quot;protobuf-json&quot; /&gt;
+</code></pre>
+<p>在 Java 代码获取 barService 并开始泛化调用:</p>
+<pre><code>GenericService barService = (GenericService) 
applicationContext.getBean(&quot;barService&quot;);
+Object result = barService.$invoke(&quot;sayHello&quot;,new 
String[]{&quot;org.apache.dubbo.protobuf.GooglePbBasic$CDubboGooglePBRequestType&quot;},
 new 
Object[]{&quot;{\&quot;double\&quot;:0.0,\&quot;float\&quot;:0.0,\&quot;bytesType\&quot;:\&quot;Base64String\&quot;,\&quot;int32\&quot;:0}&quot;});
+</code></pre>
+<h1>通过 API 方式对Goolgle Protobuf对象泛化调用</h1>
+<pre><code>ReferenceConfig&lt;GenericService&gt; reference = new 
ReferenceConfig&lt;GenericService&gt;();
+// 弱类型接口名
+reference.setInterface(GenericService.class.getName());
+reference.setInterface(&quot;com.xxx.XxxService&quot;);
+// 声明为Protobuf-json
+reference.setGeneric(Constants.GENERIC_SERIALIZATION_PROTOBUF);
+
+GenericService genericService = reference.get();
+Map&lt;String, Object&gt; person = new HashMap&lt;String, Object&gt;();
+person.put(&quot;fixed64&quot;, &quot;0&quot;);
+person.put(&quot;int64&quot;, &quot;0&quot;);
+// 参考google官方的protobuf 3 的语法,服务的每个方法中只传输一个POJO对象
+// protobuf的泛化调用只允许传递一个类型为String的json对象来代表请求参数
+String requestString = new Gson().toJson(person);
+// 返回对象是GoolgeProtobuf响应对象的json字符串。
+Object result = genericService.$invoke(&quot;sayHello&quot;, new String[] {
+    &quot;com.xxx.XxxService.GooglePbBasic$CDubboGooglePBRequestType&quot;},
+    new Object[] {requestString});
+</code></pre>
+<h1>有关GoogleProtobuf对象的处理</h1>
+<p>GoogleProtobuf对象是由Protocol契约生成,相关知识请参考<a 
href="https://developers.google.com/protocol-buffers/?hl=zh-CN";>ProtocolBuffers文档</a>。
+假如有如下Protobuf 契约</p>
+<pre><code>syntax = &quot;proto3&quot;;
+package com.xxx.XxxService.GooglePbBasic.basic;
+message CDubboGooglePBRequestType {
+    double double = 1;
+    float float = 2;
+    int32 int32 = 3;
+    bool bool = 13;
+    string string = 14;
+    bytes bytesType = 15;
+}
+
+message CDubboGooglePBResponseType {
+    string msg = 1;
+}
+
+service CDubboGooglePBService {
+    rpc sayHello (CDubboGooglePBRequestType) returns 
(CDubboGooglePBResponseType);
+}
+</code></pre>
+<p>则对应请求按照如下方法构造</p>
+<pre><code>Map&lt;String, Object&gt; person = new HashMap&lt;&gt;();
+person.put(&quot;double&quot;, &quot;1.000&quot;);
+person.put(&quot;float&quot;, &quot;1.00&quot;);
+person.put(&quot;int32&quot;,&quot;1&quot; );
+person.put(&quot;bool&quot;,&quot;false&quot; );
+//String 的对象需要经过base64编码
+person.put(&quot;string&quot;,&quot;someBaseString&quot;);
+person.put(&quot;bytesType&quot;,&quot;150&quot;);
+</code></pre>
+<h1>GoogleProtobuf服务元数据解析</h1>
+<p>Google Protobuf对象缺少标准的JSON格式,生成的服务元数据信息存在错误。
+请添加如下依赖元数据解析的依赖。</p>
+<pre><code>&lt;dependency&gt;
+    &lt;groupId&gt;org.apache.dubbo&lt;/groupId&gt;
+    &lt;artifactId&gt;dubbo-metadata-definition-protobuf&lt;/artifactId&gt;
+    &lt;version&gt;${dubbo.version}&lt;/version&gt;
+&lt;/dependency&gt;
+</code></pre>
+<p>从服务元数据中也可以比较容易构建泛化调用对象。</p>
+</div></section><footer class="footer-container"><div class="footer-body"><img 
src="/img/dubbo_gray.png"/><img class="apache" src="/img/apache_logo.png"/><div 
class="cols-container"><div class="col col-12"><h3></h3><p></p></div><div 
class="col col-4"><dl><dt>ASF</dt><dd><a href="http://www.apache.org"; 
target="_self">基金会</a></dd><dd><a href="http://www.apache.org/licenses/"; 
target="_self">证书</a></dd><dd><a 
href="http://www.apache.org/events/current-event"; 
target="_self">事件</a></dd><dd><a  [...]
+       <script 
src="https://f.alicdn.com/react/15.4.1/react-with-addons.min.js";></script>
+       <script 
src="https://f.alicdn.com/react/15.4.1/react-dom.min.js";></script>
+       <script>
+               window.rootPath = '';
+  </script>
+  <script src="/build/documentation.js"></script>
+  <!-- Global site tag (gtag.js) - Google Analytics -->
+       <script async 
src="https://www.googletagmanager.com/gtag/js?id=UA-112489517-1";></script>
+       <script>
+               window.dataLayer = window.dataLayer || [];
+               function gtag(){dataLayer.push(arguments);}
+               gtag('js', new Date());
+
+               gtag('config', 'UA-112489517-1');
+       </script>
+</body>
+</html>
\ No newline at end of file
diff --git a/zh-cn/docs/user/demos/GooglePb-generic-reference.json 
b/zh-cn/docs/user/demos/GooglePb-generic-reference.json
new file mode 100644
index 0000000..a64ca84
--- /dev/null
+++ b/zh-cn/docs/user/demos/GooglePb-generic-reference.json
@@ -0,0 +1,6 @@
+{
+  "filename": "GooglePb-generic-reference.md",
+  "__html": "<h1>GoogleProtobuf对象泛化调用</h1>\n<p>泛化接口调用方式主要用于客户端没有 API 
接口及模型类元的情况,参考 <a 
href=\"http://dubbo.apache.org/zh-cn/docs/user/demos/group-merger.html\";>泛化调用</a>。\n一般泛化调用只能用于生成的服务参数为POJO的情况,而GoogleProtobuf的对象是基于Builder生成的非正常POJO,可以通过protobuf-json泛化调用。<br>\nGoogleProtobuf序列化相关的Demo可以参考<a
 
href=\"https://github.com/vio-lin/dubbo-samples/tree/protobuf-demo\";>protobuf-demo</a></p>\n<h1>通过Spring对Goolgle
 Protobuf对象泛化调用</h1>\n<p>在Spring中配置声明generic = 
&quot;protobuf-json&quot;</p>\n<pre><co [...]
+  "link": "/zh-cn/docs/user/demos/GooglePb-generic-reference.html",
+  "meta": {}
+}
\ No newline at end of file

Reply via email to