0%

feign

feign是一个声明式的伪http客户端,它使得编写http客户端变的简单。使用Feign,只需要创建一个接口并注解。它具有可插拔的注解特性,可使用Feign注解和JAX_RS注解。Feign支持可插拔的编码器和解码器。Feign整合了Ribbon与Hystrix,并和Eureka结合,能够实现负载均衡和断路器等效果。
简而言之:

  • feign采用的基于接口的注解
  • feign整合Ribbon、Hystrix
    Read more »

ribbon

  • 负载均衡的框架
  • 支持多种协议,如http、tcp等
  • 提供负载均衡客户端

jar包

Gradle: com.netflix.ribbon:ribbon:2.3.0 外壳
Gradle: com.netflix.ribbon:ribbon-core:2.3.0 核心包
Gradle: com.netflix.ribbon:ribbon-eureka:2.3.0 和eureka的继承
Gradle: com.netflix.ribbon:ribbon-httpclient:2.3.0 http客户端
Gradle: com.netflix.ribbon:ribbon-loadbalancer:2.3.0 负载均衡器
Gradle: com.netflix.ribbon:ribbon-transport:2.3.0 其他协议的支持

Read more »

eureka架构

eureka-construct.png

DiscoveryClient

The class that is instrumental for interactions with Eureka Server.
Eureka Client is responsible for a) Registering the instance with Eureka Server b) Renewalof the lease with Eureka Server c) Cancellation of the lease from Eureka Server during shutdown
d) Querying the list of services/instances registered with Eureka Server
DiscoveryClient是和Eureka服务通信的类的实现
a)注册到Eureka server
b)租约,续约
c)服务下线
d)拉取服务列表

Read more »

ReentrantReadWriteLock

实例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class MyTest2 {
private ReadWriteLock lock = new ReentrantReadWriteLock();
public void method(){
try{
lock.readLock().lock();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("method");
}finally {
lock.readLock().unlock();
}
}

public static void main(String[] args) {
MyTest2 myTest2 = new MyTest2();
IntStream.range(0,10).forEach(i -> new Thread(myTest2::method).start());
}
}
Read more »

AQS(AbstractQueuedSynchronizer)

AQS和synchronized关键字C++的实现原理相似度是80%左右。

AbstractQueuedSynchronizer主要成员

aqs1.png

  • public class ConditionObject implements Condition, java.io.Serializable
    一个AQS可以有多个Condition对象,也就意味着有多个等待队列
  • static final class Node
    Node是对阻塞线程的封装,Node内部有一个Thread的引用。
  • private volatile int state; 同步状态,在不同的场景有不同的含义,精妙所在
    Read more »