Skip to content

Commit 4db4756

Browse files
committed
更新文档
1 parent 9cc648f commit 4db4756

File tree

3 files changed

+185
-9
lines changed

3 files changed

+185
-9
lines changed

README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44

55
ServcieFramework 定位在 **移动互联网后端** 领域,强调开发的高效性,其开发效率可以比肩Rails.
66

7-
现在代码中的pom文件用的是公司的maven仓库。更目录下有个open-source.xml,修改成pom.xml即可正常编译。
8-
### 在Maven中使用该项目
7+
ServcieFramework 目前更新频率较高,我现在一直疏于更新中央仓库的版本。所以Wiki中不再提供Maven版本。
98

10-
在你的pom.xml 文件中中添加如下引用:
9+
建议:
1110

12-
<dependency>
13-
<groupId>net.csdn</groupId>
14-
<artifactId>ServiceFramework</artifactId>
15-
<version>1.1</version>
16-
</dependency>
11+
1. 下载 https://github.com/allwefantasy/csdn_common,并且deploy自己的私有maven仓库.
12+
2. 下载ServiceFramework 通过maven deploy到自己的maven仓库。
1713

14+
现在代码中的pom文件用的是自己公司的maven仓库。根目录下有个open-source.xml,修改成pom.xml即可正常编译。
1815

16+
### 在Maven中使用该项目
1917

2018
接着确保 项目根目录下有config/application.yml,config/logging.yml 两个文件即可。示例可参看该项目中config文件夹。
2119

@@ -88,7 +86,41 @@ ServiceFramework 特点:
8886

8987
服务提供者可以针对一个http接口定义出任意个方法,每个方法都之定义一部分参数,这样可以有效方便调用者使用。
9088

89+
7. 如果你不使用Dubbo,你可以可以非常容易的调用第三方的标准HTTP接口,达到类似RPC调用的效果。
9190

91+
* 将第三方HTTP API 做个申明,例如有个搜索接口(Scala代码示例)
92+
93+
trait SearcherClient {
94+
@At(path = Array("/v2/~/~/_search"), types = Array(GET, POST))
95+
@BasicInfo(
96+
desc = "索引服务",
97+
state = State.alpha,
98+
testParams = "",
99+
testResult = "",
100+
author = "WilliamZhu",
101+
102+
)
103+
def search(params: Map[String, String], content: String, method: net.csdn.modules.http.RestRequest.Method): java.util.List[HttpTransportService.SResponse]
104+
105+
}
106+
107+
* 接着在需要使用该接口的地方调用如下代码构建SearcherClient对象。记住,这个对象只能构建一次(Scala代码示例)
108+
109+
val _searchClient = AggregateRestClient.buildClient[SearcherClient](hostAndPorts, new SearchEngineStrategy(), httpRequest)
110+
//其中,hostAndPorts 为域名和端口。
111+
//可以是多个。SearchEngineStrategy 是自定义实现如何调用后端服务,
112+
//是轮训的负载均衡还是有特别的逻辑
113+
114+
115+
* 现在可以使用了(Scala代码示例)
116+
117+
val res = _searchClient.search(
118+
url._2.toMap ++ Map("index" -> index, "type" -> ctype),
119+
query,
120+
RestRequest.Method.POST).searchResult
121+
122+
使用该种方式调用第三方API会产生Trace日志。
123+
92124
7. 服务降级限流
93125
ServiceFramework主要面向后端服务,如果没有自我保护机制,系统很容易过载而不可用。经过一定的容量规划,或者通过对接口调用平均响应耗时的监控,
94126
我们可以动态调整 ServiceFramework 的QPS限制,从而达到保护系统的目的。这些都可以通过配置以及内置的http接口完成。

ServiceFrameworkWiki-config.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<link rel="stylesheet" href="http://yandex.st/highlightjs/6.2/styles/googlecode.min.css">
2+
3+
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
4+
<script src="http://yandex.st/highlightjs/6.2/highlight.min.js"></script>
5+
6+
<script>hljs.initHighlightingOnLoad();</script>
7+
8+
9+
<script type="text/javascript">
10+
$(document).ready(function(){
11+
$("h2,h3,h4,h5,h6").each(function(i,item){
12+
$(item).attr("id","wow"+i);
13+
$("#category").append("<li><a href=\"#wow"+i+"\">"+$(this).text()+"</a></li>");
14+
});
15+
});
16+
</script>
17+
18+
19+
20+
<style>
21+
pre code {
22+
break-word: break-all;
23+
word-wrap: break-word;
24+
}
25+
</style>
26+
27+
#ServiceFramework Wiki
28+
29+
### 配置文件
30+
31+
ServiceFramework 所有的配置文件位于config目录下。其实只有两个配置文件,一个application.yml,
32+
一个logging.yml.分别配置应用和日志。
33+
34+
一个完整的application.yml
35+
36+
```
37+
#mode
38+
mode:
39+
development
40+
#mode=production
41+
42+
###############datasource config##################
43+
#mysql,mongodb,redis等数据源配置方式
44+
development:
45+
datasources:
46+
mysql:
47+
host: 127.0.0.1
48+
port: 3306
49+
database: tag_engine
50+
username: tag
51+
password: tag
52+
disable: true
53+
mongodb:
54+
host: 127.0.0.1
55+
port: 27017
56+
database: tag_engine
57+
redis:
58+
host: 127.0.0.1
59+
port: 6379
60+
61+
production:
62+
datasources:
63+
mysql:
64+
host: 127.0.0.1
65+
port: 3306
66+
database: tag_engine
67+
username: tag
68+
password: tag
69+
mongodb:
70+
host: 127.0.0.1
71+
port: 27017
72+
database: tag_engine
73+
redis:
74+
host: 127.0.0.1
75+
port: 6379
76+
77+
orm:
78+
show_sql: true
79+
pool_min_size: 5
80+
pool_max_size: 10
81+
timeout: 300
82+
max_statements: 50
83+
idle_test_period: 3000
84+
###############application config##################
85+
application:
86+
controller: com.example.controller
87+
model: com.example.model
88+
service: com.example.service
89+
util: com.example.util
90+
test: test.com.example
91+
92+
93+
###############http config##################
94+
http:
95+
port: 9400
96+
97+
98+
99+
###############validator config##################
100+
#如果需要添加验证器,只要配置好类全名即可
101+
#替换验证器实现,则替换相应的类名即可
102+
#warning: 自定义验证器实现需要线程安全
103+
104+
validator:
105+
format: net.csdn.validate.impl.Format
106+
numericality: net.csdn.validate.impl.Numericality
107+
presence: net.csdn.validate.impl.Presence
108+
uniqueness: net.csdn.validate.impl.Uniqueness
109+
length: net.csdn.validate.impl.Length
110+
associated: net.csdn.validate.impl.Associated
111+
112+
################ 数据库类型映射 ####################
113+
type_mapping: net.csdn.jpa.type.impl.MysqlType
114+
115+
```
116+
117+
对于数据库等的配置默认区分开发,生产,测试。单元测试强制使用测试环境。
118+
119+
除了默认的的一些配置,你可以随意按标准的yaml格式添加配置,在实际代码中,你可以通过下面的方式获取
120+
配置
121+
122+
首先注入Settings类
123+
124+
@Inject
125+
private Settings settings;
126+
127+
然后就可以如下使用了:
128+
129+
boolean enable = settings.getAsBoolean("foo.bar.yes",false)
130+
131+
132+
在ServiceFramework中,Controller,Service,Util,Model等是需要在配置文件中明确指定的。类似配置如下:
133+
134+
application:
135+
controller: com.example.controller
136+
model: com.example.model
137+
service: com.example.service
138+
util: com.example.util
139+
test: test.com.example
140+
141+
142+
理论上,ServiceFramework的配置就是数据库配置类的扫描路径配置。
143+
144+

open-source.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>net.csdn</groupId>
4444
<artifactId>csdn-common</artifactId>
45-
<version>1.3</version>
45+
<version>1.5</version>
4646
</dependency>
4747

4848
<dependency>

0 commit comments

Comments
 (0)