??xml version="1.0" encoding="utf-8" standalone="yes"?>78色国产精品,亚洲一区在线播放,а√天堂中文资源在线bthttp://www.aygfsteel.com/paulwong/category/55108.htmlzh-cnSun, 17 Dec 2023 12:04:15 GMTSun, 17 Dec 2023 12:04:15 GMT60Micro Fronthttp://www.aygfsteel.com/paulwong/archive/2023/12/14/451321.htmlpaulwongpaulwongThu, 14 Dec 2023 01:58:00 GMThttp://www.aygfsteel.com/paulwong/archive/2023/12/14/451321.htmlhttp://www.aygfsteel.com/paulwong/comments/451321.htmlhttp://www.aygfsteel.com/paulwong/archive/2023/12/14/451321.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/451321.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/451321.htmlhttps://medium.com/starbugs/%E5%BE%AE%E6%9C%8D%E5%8B%99%E5%BE%88%E5%A4%AF-%E9%82%A3%E4%BD%A0%E6%9C%89%E8%81%BD%E9%81%8E%E5%BE%AE%E5%89%8D%E7%AB%AF%E5%97%8E-%E5%88%9D%E6%8E%A2-micro-frontends-%E6%9E%B6%E6%A7%8B-e0a8469be601

一ha?Micro Frontends 的世?br />https://blog.techbridge.cc/2019/01/12/micro-frontends-concept/


Micro Frontends
extending the microservice idea to frontend development
https://micro-frontends.org/


paulwong 2023-12-14 09:58 发表评论
]]>
SPRING CLOUD CONFIG有界面的配置理中心http://www.aygfsteel.com/paulwong/archive/2021/10/07/436000.htmlpaulwongpaulwongThu, 07 Oct 2021 08:55:00 GMThttp://www.aygfsteel.com/paulwong/archive/2021/10/07/436000.htmlhttp://www.aygfsteel.com/paulwong/comments/436000.htmlhttp://www.aygfsteel.com/paulwong/archive/2021/10/07/436000.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/436000.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/436000.html

https://dyc87112.github.io/spring-cloud-config-admin/

paulwong 2021-10-07 16:55 发表评论
]]>
微服务架构设计模?/title><link>http://www.aygfsteel.com/paulwong/archive/2021/01/06/435766.html</link><dc:creator>paulwong</dc:creator><author>paulwong</author><pubDate>Wed, 06 Jan 2021 06:44:00 GMT</pubDate><guid>http://www.aygfsteel.com/paulwong/archive/2021/01/06/435766.html</guid><wfw:comment>http://www.aygfsteel.com/paulwong/comments/435766.html</wfw:comment><comments>http://www.aygfsteel.com/paulwong/archive/2021/01/06/435766.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/paulwong/comments/commentRss/435766.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/paulwong/services/trackbacks/435766.html</trackback:ping><description><![CDATA[微服务架构及设计模式<br /><a target="_blank">http://dockone.io/article/9680</a><br /><br />微服务架?0个最重要的设计模?br /><a target="_blank">https://developer.51cto.com/art/202012/635852.htm</a><br /><br />GitHub标星127KQ字节内部必?#8220;微服务架构设计模?#8221;<br /><a target="_blank">https://blog.csdn.net/a159357445566/article/details/110006542</a><br /><br />微服务架构及其最重要?0个设计模?br /><a target="_blank">https://www.infoq.cn/article/Kdw69bdimlX6FSGz1bg3</a><br /><br />Effective Microservices: 10 Best Practices<br /><a target="_blank">https://towardsdatascience.com/effective-microservices-10-best-practices-c6e4ba0c6ee2</a><br /><br />Microservice Architecture and its 10 Most Important Design Patterns<br /><a target="_blank">https://towardsdatascience.com/microservice-architecture-and-its-10-most-important-design-patterns-824952d7fa41</a><br /><br /><br /><br /><br /><img src ="http://www.aygfsteel.com/paulwong/aggbug/435766.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/paulwong/" target="_blank">paulwong</a> 2021-01-06 14:44 <a href="http://www.aygfsteel.com/paulwong/archive/2021/01/06/435766.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ZSpring Cloud的快速开发脚手架&最佛_跉|ȝhttp://www.aygfsteel.com/paulwong/archive/2020/10/09/435685.htmlpaulwongpaulwongFri, 09 Oct 2020 02:48:00 GMThttp://www.aygfsteel.com/paulwong/archive/2020/10/09/435685.htmlhttp://www.aygfsteel.com/paulwong/comments/435685.htmlhttp://www.aygfsteel.com/paulwong/archive/2020/10/09/435685.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435685.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435685.html Spring Cloud 你懂?/td> Keycloak 微服务认证授?/td> Jenkins 持箋集成 SonarQube 代码质量控制

https://gitee.com/itmuch/spring-cloud-yes

paulwong 2020-10-09 10:48 发表评论
]]>
Spring Cloud异步场景分布式事务怎样做?试试RocketMQhttp://www.aygfsteel.com/paulwong/archive/2020/07/15/435596.htmlpaulwongpaulwongWed, 15 Jul 2020 02:33:00 GMThttp://www.aygfsteel.com/paulwong/archive/2020/07/15/435596.htmlhttp://www.aygfsteel.com/paulwong/comments/435596.htmlhttp://www.aygfsteel.com/paulwong/archive/2020/07/15/435596.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435596.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435596.html
分布式的场景下,订单服务在一个JVM下,U分服务在另一个JVM下,两者要如何才能辑ֈ数据一_原子Q性?


https://zlt2000.gitee.io/2019-09-23-rocketmq-transaction/


paulwong 2020-07-15 10:33 发表评论
]]>
!!zlt-microservices-platformhttp://www.aygfsteel.com/paulwong/archive/2020/07/15/435595.htmlpaulwongpaulwongWed, 15 Jul 2020 02:15:00 GMThttp://www.aygfsteel.com/paulwong/archive/2020/07/15/435595.htmlhttp://www.aygfsteel.com/paulwong/comments/435595.htmlhttp://www.aygfsteel.com/paulwong/archive/2020/07/15/435595.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435595.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435595.html1. M架构?/h2>

mark


2. 功能介绍

mark




https://github.com/zlt2000/microservices-platform 

https://zlt2000.gitee.io/

产品文档Q付费,微信dQ:
https://www.kancloud.cn/zlt2000/microservices-platform




paulwong 2020-07-15 10:15 发表评论
]]>
APM资源http://www.aygfsteel.com/paulwong/archive/2019/12/30/435006.htmlpaulwongpaulwongMon, 30 Dec 2019 08:50:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/12/30/435006.htmlhttp://www.aygfsteel.com/paulwong/comments/435006.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/12/30/435006.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435006.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435006.htmlhttps://my.oschina.net/10000000000/blog/3119697

监控理之Spring Boot Admin使用
https://my.oschina.net/xiedeshou/blog/2051625


https://my.oschina.net/janlle/blog/3040749

paulwong 2019-12-30 16:50 发表评论
]]>
微服?|关http://www.aygfsteel.com/paulwong/archive/2019/12/30/435005.htmlpaulwongpaulwongMon, 30 Dec 2019 08:44:00 GMThttp://www.aygfsteel.com/paulwong/archive/2019/12/30/435005.htmlhttp://www.aygfsteel.com/paulwong/comments/435005.htmlhttp://www.aygfsteel.com/paulwong/archive/2019/12/30/435005.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/435005.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/435005.htmlhttps://felord.cn/kong-api-gateway.html

云原生网?Kong 和Kong 理UI Konga的完全安装攻?br />https://felord.cn/kong-and-konga-install.html






paulwong 2019-12-30 16:44 发表评论
]]>
使用Spring Cloud Security OAuth2搭徏授权服务http://www.aygfsteel.com/paulwong/archive/2016/09/16/431797.htmlpaulwongpaulwongFri, 16 Sep 2016 10:22:00 GMThttp://www.aygfsteel.com/paulwong/archive/2016/09/16/431797.htmlhttp://www.aygfsteel.com/paulwong/comments/431797.htmlhttp://www.aygfsteel.com/paulwong/archive/2016/09/16/431797.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/431797.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/431797.htmlSpring Cloud Security OAuth2 ?Spring ?OAuth2 的开源实玎ͼ优点是能与Spring Cloud技术线无缝集成Q如果全部用默认配|,开发者只需要添加注解就能完?OAuth2 授权服务的搭建?/p>

1. d依赖

授权服务是基于Spring Security的,因此需要在目中引入两个依赖:

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-security</artifactId>
</dependency>

<dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-oauth2</artifactId>
 </dependency>


前者ؓ SecurityQ后者ؓSecurity的OAuth2扩展?/p>

2. d注解和配|?/h1>

在启动类中添?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@EnableAuthorizationServer注解Q?br />

@SpringBootApplication
@EnableAuthorizationServer
public class AlanOAuthApplication {
    public static void main(String[] args) {
        SpringApplication.run(AlanOAuthApplication.class, args);
    }
}


完成q些我们的授权服务最基本的骨架就已经搭徏完成了。但是要惌通整个流E,我们必须分配 client_idclient_secret才行。Spring Security OAuth2的配|方法是~写@Configurationcȝ?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">AuthorizationServerConfigurerAdapterQ然后重?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">void configure(ClientDetailsServiceConfigurer clients)ҎQ如Q?br />

@Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
        clients.inMemory() // 使用in-memory存储
                .withClient("client") // client_id
                .secret("secret") // client_secret
                .authorizedGrantTypes("authorization_code") // 该client允许的授权类?/span>
                .scopes("app"); // 允许的授权范?/span>
    }


3. 授权程

讉K授权面Q?br />

localhost:8080/oauth/authorize?client_id=client&response_type=code&redirect_uri=http://www.baidu.com


此时览器会让你输入用户名密码,q是因ؓ Spring Security 在默认情况下会对所有URLdBasic Auth认证。默认的用户名ؓuser, 密码是随机生成的Q在控制台日志中可以看到?/p>

oauth2

画风虽然很简陋,但是基本功能都具备了。点?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">Authorize后,览器就会重定向到百度,q带?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">code参数Q?/p>

q里写图片描q? title=

拿到code以后Q就可以调用

POST/GET http://client:secret@localhost:8080/oauth/token
  • 1

来换?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">access_token了:

curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d 'grant_type=authorization_code&code=Li4NZo&redirect_uri=http://www.baidu.com' "http://client:secret@localhost:8080/oauth/token"

q回如下Q?br />

{
  "access_token": "32a1ca28-bc7a-4147-88a1-c95abcc30556",
  "token_type": "bearer",
  "expires_in": 2591999,
  "scope": "app"
}

到此我们最最基本的授权服务就搭徏完成了。然而,q仅仅是个demoQ如果要在生产环境中使用Q还需要做更多的工作?/p>

4. 使用MySQL存储access_token和client信息

把授权服务器中的数据存储到数据库中ƈ不难Q因?Spring Cloud Security OAuth 已经为我们设计好了一套Schema和对应的DAO对象。但在用之前,我们需要先对相关的cL一定的了解?/p>

4.1 相关接口

Spring Cloud Security OAuth2通过DefaultTokenServicescL完成token生成、过期等 OAuth2 标准规定的业务逻辑Q?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">DefaultTokenServices又是通过TokenStore接口完成对生成数据的持久化。在上面的demo中,TokenStore的默认实CؓInMemoryTokenStoreQ即内存存储?对于Client信息Q?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">ClientDetailsService接口负责从存储仓库中d数据Q在上面的demo中默认用的也是InMemoryClientDetialsService实现cR说到这里就能看出,要想使用数据库存储,只需要提供这些接口的实现cd可。庆q的是,框架已经为我们写好JDBC实现了,?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">JdbcTokenStore?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">JdbcClientDetailsService?/p>

4.2

要想使用q些JDBC实现Q首先要。框架ؓ我们提前设计好了schema, 在github上:https://github.com/spring-projects/spring-security-oauth/blob/master/spring-security-oauth2/src/test/resources/schema.sql

在用这套表l构之前要注意的是,对于MySQL来说Q默认徏表语句中主键是varchar(255)cdQ在mysql中执行会报错Q原因是mysql对varchar主键长度有限制。所以这里改?28卛_。其ơ,语句中会有某些字DؓLONGVARBINARYcdQ它对应mysql?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">blobcdQ也需要修改一下?/p>

4.3 配置

数据库徏好后Q下一步就是配|框架用JDBC实现。方法还是编?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@Configurationcȝ?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">AuthorizationServerConfigurerAdapterQ?br />

@Autowired
    private AuthenticationManager authenticationManager;

    @Autowired
    private DataSource dataSource;
    @Bean // 声明TokenStore实现
    public TokenStore tokenStore() {
        return new JdbcTokenStore(dataSource);
    }
    @Bean // 声明 ClientDetails实现
    public ClientDetailsService clientDetails() {
        return new JdbcClientDetailsService(dataSource);
    }
    @Override // 配置框架应用上述实现
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
        endpoints.authenticationManager(authenticationManager);
        endpoints.tokenStore(tokenStore());

        // 配置TokenServices参数
        DefaultTokenServices tokenServices = new DefaultTokenServices();
        tokenServices.setTokenStore(endpoints.getTokenStore());
        tokenServices.setSupportRefreshToken(false);
        tokenServices.setClientDetailsService(endpoints.getClientDetailsService());
        tokenServices.setTokenEnhancer(endpoints.getTokenEnhancer());
        tokenServices.setAccessTokenValiditySeconds( (int) TimeUnit.DAYS.toSeconds(30)); // 30?/span>
        endpoints.tokenServices(tokenServices);
    }

完成q些后,框架׃中间生的数据写到mysql中了?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">oauth_client_details是client表,可以直接在该表中d记录来添加client: 
q里写图片描q? title=

4.4 需要注意的地方

q里不得不说 Spring 设计有一个奇葩地的方。注意看oauth_access_token表是存放讉K令牌的,但是q没有直接在字段中存放token。Spring 使用OAuth2AccessToken来抽象与令牌有关的所有属性,在写入到数据库时Q?strong style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 16px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;">Spring该对象通过JDK自带的序列化机制序列成字?/strong>直接保存C该表?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">token字段中。也是_如果只看数据表你是看不出access_token的值是多少Q过期时间等信息的。这q资源服务器的实现带来了麻烦。我们的资源提供方ƈ没有使用Spring SecurityQ也不想引入 Spring Security 的Q何依赖,q时候就只能?nbsp;DefaultOAuth2AccessToken的源码copy到资源提供方的项目中Q然后读?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">token字段q反序列化还原对象来获取token信息。但是如果这样做q会遇到反序列化兼容性的问题Q具体解x法参考我另一博?http://blog.csdn.net/neosmith/article/details/52539614

5. ȝ

x一个能在生产环境下使用的授权服务就搭徏好了。其实我们在实际使用时应该适当定制JdbcTokenStore?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">ClientDetailsService来实适应业务需要,甚至可以直接?开始实现接口,完全不用框架提供的实现。另外,Spring 直接?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">DefaultOAuth2AccessToken序列化成字节保存到数据库中的设计Q我认ؓ是非怸合理的。或许设计者的初衷是保?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">access_tokenQ但是通过加密的方法也可以实现Q完全不应该直接扔字节。不q通过定制TokenStore接口Q我们可以用自q表结构而不拘惔于默认实现?br />
http://blog.csdn.net/tracker_w/article/category/6360121

http://blog.csdn.net/neosmith/article/details/52539927



paulwong 2016-09-16 18:22 发表评论
]]>
使用Spring Cloud Feign作ؓHTTP客户端调用远EHTTP服务http://www.aygfsteel.com/paulwong/archive/2016/09/16/431796.htmlpaulwongpaulwongFri, 16 Sep 2016 10:13:00 GMThttp://www.aygfsteel.com/paulwong/archive/2016/09/16/431796.htmlhttp://www.aygfsteel.com/paulwong/comments/431796.htmlhttp://www.aygfsteel.com/paulwong/archive/2016/09/16/431796.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/431796.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/431796.html在Spring Cloud Netflix栈中Q各个微服务都是以HTTP接口的Ş式暴露自w服务的Q因此在调用q程服务时就必须使用HTTP客户端。我们可以用JDK原生?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">URLConnection、Apache?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">Http Client、Netty的异步HTTP Client, Spring?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">RestTemplate。但是,用v来最方便、最优雅的还是要属Feign了?/p>

Feign?/h1>

Feign是一U声明式、模板化的HTTP客户端。在Spring Cloud中用Feign, 我们可以做到使用HTTPhq程服务时能与调用本地方法一L~码体验Q开发者完全感知不到这是远E方法,更感知不到这是个HTTPh。比如:

@Autowired
private AdvertGropRemoteService service; // q程服务

public AdvertGroupVO foo(Integer groupId) {
    return service.findByGroupId(groupId); // 通过HTTP调用q程服务
}

开发者通过service.findByGroupId()p完成发送HTTPh和解码HTTPq回l果q封装成对象的过E?/p>

Feign的定?/h1>

Z让Feign知道在调用方法时应该向哪个地址发请求以及请求需要带哪些参数Q我们需要定义一个接口:

@FeignClient(name = "ea")  //  [A]
public interface AdvertGroupRemoteService {

    @RequestMapping(value = "/group/{groupId}", method = RequestMethod.GET) // [B]
    AdvertGroupVO findByGroupId(@PathVariable("groupId") Integer adGroupId) // [C]

    @RequestMapping(value = "/group/{groupId}", method = RequestMethod.PUT)
    void update(@PathVariable("groupId") Integer groupId, @RequestParam("groupName") String groupName)

A: @FeignClient用于通知Feignlg对该接口q行代理(不需要编写接口实?Q用者可直接通过@Autowired注入?/p>

B: @RequestMapping表示在调用该Ҏ旉要向/group/{groupId}发?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">GETh?/p>

C: @PathVariable?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">SpringMVC中对应注解含义相同?/p>

Spring Cloud应用在启动时QFeign会扫描标?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@FeignClient注解的接口,生成代理Qƈ注册到Spring容器中。生成代理时Feign会ؓ每个接口Ҏ创徏一?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">RequetTemplate对象Q该对象装了HTTPh需要的全部信息Q请求参数名、请求方法等信息都是在这个过E中定的,Feign的模板化׃现在q里?/p>

在本例中Q我们将Feign与Eureka和Ribbonl合使用Q?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@FeignClient(name = "ea")意ؓ通知Feign在调用该接口Ҏ时要向Eureka中查询名?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">ea的服务,从而得到服务URL?/p>

Feign的Encoder、Decoder和ErrorDecoder

Feign方法签名中Ҏ参数对象序列化ؓh参数攑ֈHTTPh中的q程Q是q码器(Encoder)完成的。同理,HTTP响应数据反序列化为java对象是由解码?Decoder)完成的?/p>

默认情况下,Feign会将标有@RequestParam注解的参数{换成字符串添加到URL中,没有注解的参数通过Jackson转换成json攑ֈh体中。注意,如果?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">@RequetMapping中的method请求方式指定ؓPOSTQ那么所有未标注解的参数会被忽略,例如Q?br />

@FeignClient(name = "ea")  //  [A]
public interface AdvertGroupRemoteService {

    @RequestMapping(value = "/group/{groupId}", method = RequestMethod.GET) // [B]
    AdvertGroupVO findByGroupId(@PathVariable("groupId") Integer adGroupId) // [C]

    @RequestMapping(value = "/group/{groupId}", method = RequestMethod.PUT)
    void update(@PathVariable("groupId") Integer groupId, @RequestParam("groupName") String groupName)

此时因ؓ声明的是GETh没有h体,所?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">obj参数׃被忽略?/p>

在Spring Cloud环境下,Feign的Encoder*只会用来~码没有d注解的参?。如果你自定义了Encoder, 那么只有在编?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">obj参数时才会调用你的Encoder。对于Decoder, 默认会委托给SpringMVC中的MappingJackson2HttpMessageConverterc进行解码。只有当状态码不在200 ~ 300之间时ErrorDecoder才会被调用。ErrorDecoder的作用是可以ҎHTTP响应信息q回一个异常,该异常可以在调用Feign接口的地方被捕获到。我们目前就通过ErrorDecoder来Feign接口抛出业务异常以供调用者处理?/p>

Feign的HTTP Client

Feign在默认情况下使用的是JDK原生?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">URLConnection发送HTTPhQ没有连接池Q但是对每个地址会保持一个长q接Q即利用HTTP?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">persistence connection 。我们可以用Apache的HTTP Client替换Feign原始的http client, 从而获取连接池、超时时间等与性能息息相关的控制能力。Spring Cloud?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">Brixtion.SR5版本开始支持这U替换,首先在项目中声明Apache HTTP Client?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">feign-httpclient依赖Q?br />

@RequestMapping(value = "/group/{groupId}", method = RequestMethod.GET)
void update(@PathVariable("groupId") Integer groupId, @RequestParam("groupName") String groupName, DataObject obj);

然后?code style="box-sizing: border-box; font-family: "Source Code Pro", monospace; font-size: 13.5px; padding: 2px 4px; color: #3f3f3f; white-space: nowrap; border-radius: 0px; margin: 0px; border: 0px; outline: 0px; vertical-align: baseline; word-break: break-word; background: rgba(128, 128, 128, 0.0745098);">application.properties中添加:

feign.httpclient.enabled=true

ȝ

通过FeignQ?我们能把HTTPq程调用对开发者完全透明Q得C调用本地Ҏ一致的~码体验。这一点与阉KDubbo中暴露远E服务的方式cMQ区别在于Dubbo是基于私有二q制协议Q而Feign本质上还是个HTTP客户端。如果是在用Spring Cloud Netflix搭徏微服务,那么Feign无疑是最佳选择?br />
http://blog.csdn.net/tracker_w/article/category/6360121
http://blog.csdn.net/neosmith/article/details/52449921



paulwong 2016-09-16 18:13 发表评论
]]>
微服务框架Spring Cloudhttp://www.aygfsteel.com/paulwong/archive/2016/09/11/431788.htmlpaulwongpaulwongSun, 11 Sep 2016 12:49:00 GMThttp://www.aygfsteel.com/paulwong/archive/2016/09/11/431788.htmlhttp://www.aygfsteel.com/paulwong/comments/431788.htmlhttp://www.aygfsteel.com/paulwong/archive/2016/09/11/431788.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/431788.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/431788.html2016

paulwong 2016-09-11 20:49 发表评论
]]>
JHipsterhttp://www.aygfsteel.com/paulwong/archive/2016/09/11/431787.htmlpaulwongpaulwongSun, 11 Sep 2016 08:40:00 GMThttp://www.aygfsteel.com/paulwong/archive/2016/09/11/431787.htmlhttp://www.aygfsteel.com/paulwong/comments/431787.htmlhttp://www.aygfsteel.com/paulwong/archive/2016/09/11/431787.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/431787.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/431787.htmlhttp://jhipster.cn/

paulwong 2016-09-11 16:40 发表评论
]]>
spring cloud目d配置理http://www.aygfsteel.com/paulwong/archive/2016/09/11/431785.htmlpaulwongpaulwongSun, 11 Sep 2016 08:26:00 GMThttp://www.aygfsteel.com/paulwong/archive/2016/09/11/431785.htmlhttp://www.aygfsteel.com/paulwong/comments/431785.htmlhttp://www.aygfsteel.com/paulwong/archive/2016/09/11/431785.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/431785.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/431785.htmlspring cloud config server配置好了数据库连接信息,q个目dconfigQ获取连接信息。这里以mybtis作ؓ列子。从服务器读取jdbc信息后,q行mybatisE序?br />
认服务是否成功
http://localhost:8888/demo-config/test
{"name":"demo-config","profiles":["test"],"label":"master","version":"02d28ad4925aa9bd1bf8a48d2edbf04ce61aa45a","propertySources":[{"name":"https://git.oschina.net/penghaozhong/demo.git/demo-config-repo/demo-config-test.properties","source":{"jdbc.url":"jdbc:mysql://localhost:3306/demo?characterEncoding=UTF-8","jdbc.username":"root","jdbc.driver":"com.mysql.jdbc.Driver","jdbc.password":"xxxxxx","jdbc.type":"mysql"}}]}

    2. 配置d配置文g

  



在bootstrap.properties中添加读取配|管理的地址?br />
3. d配置文g属性,q里采用@ConfigurationProperties
/**
 * d数据库配|文?br /> * 
@author penghaozhong
 *
 
*/
@ConfigurationProperties(prefix = DataSourceProperties.PREFIX, ignoreUnknownFields = false)
public  class  DataSourceProperties {
    
        public DataSourceProperties() {
        super();
    }
        //对应配置文g里的配置?/span>
        public final static String PREFIX="jdbc";    
        
        private String type; 
        private String driver; 
        private String url; 
        private String username; 
        private String password;
        
        public String getType() {
            return type;
        }
        public void setType(String type) {
            this.type = type;
        }
        public String getDriver() {
            return driver;
        }
        public void setDriver(String driver) {
            this.driver = driver;
        }
        public String getUrl() {
            return url;
        }
        public void setUrl(String url) {
            this.url = url;
        }
        public String getUsername() {
            return username;
        }
        public void setUsername(String username) {
            this.username = username;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }

}


4. 配置mybatis
@Configuration
@MapperScan("com.phz.test.spring.cloud.demo")
@EnableConfigurationProperties(DataSourceProperties.class)
@EnableTransactionManagement
public class MybatisDataSource {

    // mybaits mapper xml搜烦路径
    private final static String MAPPERLOCATIONS = "classpath:/mappings/**/*.xml";
    private final static String CONFIGLOCATION = "classpath:/mybatis-config.xml";

    @Autowired
    private  DataSourceProperties dataSourceProperties;
    private DruidDataSource datasource = null;

    @Bean(destroyMethod = "close")
    public  DataSource dataSource(){
        datasource = new DruidDataSource();  
        datasource.setUrl(dataSourceProperties.getUrl());
        datasource.setDbType(dataSourceProperties.getType());
        datasource.setDriverClassName(dataSourceProperties.getDriver());
        datasource.setUsername(dataSourceProperties.getUsername());
        datasource.setPassword(dataSourceProperties.getPassword());
        return datasource;
    }

    @PreDestroy
    public void close() {
        if(datasource != null){
            datasource.close();
        }
    }

    @Bean
    public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource());
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        sqlSessionFactoryBean.setMapperLocations(resolver.getResources(MAPPERLOCATIONS));
        sqlSessionFactoryBean.setConfigLocation(resolver.getResource(CONFIGLOCATION));
        sqlSessionFactoryBean.setTypeAliasesPackage("com.phz.test.spring.cloud.demo.entity");
        return sqlSessionFactoryBean.getObject();
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        return new DataSourceTransactionManager(dataSource());
    }

}













paulwong 2016-09-11 16:26 发表评论
]]>
MICROSERVICE 资源http://www.aygfsteel.com/paulwong/archive/2016/09/01/431723.htmlpaulwongpaulwongThu, 01 Sep 2016 13:46:00 GMThttp://www.aygfsteel.com/paulwong/archive/2016/09/01/431723.htmlhttp://www.aygfsteel.com/paulwong/comments/431723.htmlhttp://www.aygfsteel.com/paulwong/archive/2016/09/01/431723.html#Feedback0http://www.aygfsteel.com/paulwong/comments/commentRss/431723.htmlhttp://www.aygfsteel.com/paulwong/services/trackbacks/431723.html
主要有eureka做服务发现、config做分布式配置、zuul做api-gateway、feign做客L负蝲均衡、hystrix做断路器、turbine做聚合的monitor、graphite做指标监控?/span>

http://blog.csdn.net/liaokailin/article/category/6212338


MICROSERVICE WITH SPRING-CLOUD.
https://github.com/kennyk65/Microservices-With-Spring-Student-Files




!!!spring-cloud-study
http://git.oschina.net/itmuch/spring-cloud-study

paulwong 2016-09-01 21:46 发表评论
]]>
վ֩ģ壺 | | | | | | ϸ| | | | | Ͽ| ܿ| ɽ| ϰ| | Ӵ| | ƺ| ϰ| | ų| | | | ׷| | Ϳ| ԭƽ| | մ| | | | | | | | | ľ| |