<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>案例介绍 on Apache Dubbo</title><link>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/</link><description>Recent content in 案例介绍 on Apache Dubbo</description><generator>Hugo</generator><language>zh-cn</language><atom:link href="https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/index.xml" rel="self" type="application/rss+xml"/><item><title>Http Proxy 案例介绍</title><link>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/http_proxy/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/http_proxy/</guid><description>&lt;h3 id="http-代理">HTTP 代理&lt;/h3>
&lt;p>HTTP 代理案例展示了 Pixiu 接收外界 HTTP 请求然后转发给背后的 HTTP Server 的功能。&lt;/p>
&lt;p>&lt;img alt="img" src="https://deploy-preview-3203--dubbo.netlify.app/imgs/pixiu/user/samples/http_proxy.png">&lt;/p>
&lt;p>案例代码具体查看 &lt;code>/samples/http/simple&lt;/code>。案例中的目录结构和作用如下所示：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>- pixiu # pixiu 配置文件
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>- server # http server
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>- test # client or unit test
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>我们来具体看一下有关 pixiu 的具体配置文件。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>static_resources:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> listeners:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - name: &amp;#34;net/http&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> protocol_type: &amp;#34;HTTP&amp;#34; # 使用 HTTP Listener
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> address:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> socket_address:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> address: &amp;#34;0.0.0.0&amp;#34; # 监听地址设置为 0.0.0.0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> port: 8888 # 端口设置为 8888
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> filter_chains:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> filters:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - name: dgp.filter.httpconnectionmanager # NetworkFilter 设置为 httpconnectionmanager
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> config:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> route_config:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> routes:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - match:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> prefix: &amp;#34;/user&amp;#34; # 设置路由规则，将 /user 前缀的请求转发给名称为 user 的 cluster 集群
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> route:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cluster: &amp;#34;user&amp;#34;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cluster_not_found_response_code: 505
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> http_filters:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - name: dgp.filter.http.httpproxy # 使用 dgp.filter.http.httpproxy 这个 HttpFilter 来进行转发
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> config:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> clusters:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - name: &amp;#34;user&amp;#34; # 配置一个名称为 user 的 集群，其中有一个实例，地址是 127.0.0.1:1314
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> lb_policy: &amp;#34;random&amp;#34; 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> endpoints:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> - id: 1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> socket_address:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> address: 127.0.0.1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> port: 1314
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>可以先启动 &lt;code>Server&lt;/code> 文件夹下的 Http Server，然后再使用如下命令启动 &lt;code>Pixiu&lt;/code>，最后执行 test 文件夹下的单元测试。注意，-c 后是本地配置文件的绝对路径。&lt;/p></description></item><item><title>Http to Dubbo 案例介绍</title><link>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/http_to_dubbo/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/http_to_dubbo/</guid><description>&lt;p>欢迎认领补充此文档。&lt;/p></description></item><item><title>mock 案例介绍</title><link>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/mock/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/mock/</guid><description>&lt;h1 id="mock-request">Mock request&lt;/h1>
&lt;h2 id="simple-demo">Simple Demo&lt;/h2>
&lt;h3 id="api-config">Api Config&lt;/h3>
&lt;p>&lt;a href="https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/https/">https.md&lt;/a>yaml
name: pixiu
description: pixiu sample
resources:&lt;/p>
&lt;ul>
&lt;li>path: &amp;lsquo;/api/v1/test-dubbo/mock&amp;rsquo;
type: restful
description: mock
methods:
&lt;ul>
&lt;li>httpVerb: GET
enable: true
mock: true
timeout: 1000ms
inboundRequest:
requestType: http&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>### Request
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>```bash
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>curl localhost:8888/api/v1/test-dubbo/mock -X GET 
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="response">Response&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-json" data-lang="json">&lt;span style="display:flex;">&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#268bd2">&amp;#34;message&amp;#34;&lt;/span>: &lt;span style="color:#2aa198">&amp;#34;mock success&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="todo">TODO&lt;/h2>
&lt;p>我们计划在未来能够配置自定义结果。不仅通过API配置的方式，还会创建匹配规则。&lt;/p>
&lt;p>&lt;a href="https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/">Previous&lt;/a>&lt;/p></description></item><item><title>SpringCloud</title><link>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/springcloud/springcloud-springcloud/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/springcloud/springcloud-springcloud/</guid><description>&lt;h1 id="快速开始">快速开始&lt;/h1>
&lt;p>启动 Nacos [Docker 环境]：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#b58900">cd&lt;/span> samples/springcloud/docker
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>run docker-compose.yml/services
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>启动 SpringCloud [Java 环境]：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#b58900">cd&lt;/span> samples/springcloud/server
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#586e75"># the port is 8074&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>run auth-service
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#586e75"># the port is 8071&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>run user-service
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>启动 Pixiu:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>go run cmd/pixiu/*.go gateway start -c samples/springcloud/pixiu/conf.yaml
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>通过 Pixiu 调用 SpringCloud 服务：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#586e75"># the serviceId is `user-provider`&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>curl http://localhost:8888/user-service/echo/Pixiu
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#586e75"># the serviceId is `auth-provider`&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>curl http://localhost:8888/auth-service/echo/Pixiu
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>控制台输出结果：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>Hello Nacos Discovery Pixiu
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Https 案例介绍</title><link>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/https/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://deploy-preview-3203--dubbo.netlify.app/zh-cn/overview/reference/pixiu/other/user/samples/https/</guid><description>&lt;p>欢迎认领补充此文档。&lt;/p></description></item></channel></rss>