mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-14 10:26:26 +00:00
test[loadbalancer]: start cached ConsistentHashConsumer test
This commit is contained in:
@@ -39,7 +39,7 @@ public class ProviderTest {
|
||||
* RPC教程:
|
||||
* 1.首先必须保证启动zookeeper
|
||||
* 2.启动服务提供者,startProvider0,startProvider1,startProvider2
|
||||
* 3.启动服务消费者,startSyncRandomConsumer,startAsyncRandomConsumer,startConsistentSessionConsumer
|
||||
* 3.启动服务消费者,startSyncRandomConsumer,startAsyncRandomConsumer,startConsistentHashConsumer, startCachedConsistentHashConsumer
|
||||
* 4.每个消费者都是通过不同的策略消费,注意区别
|
||||
*/
|
||||
@Test
|
||||
@@ -108,8 +108,8 @@ public class ProviderTest {
|
||||
* 一致性hash算法消费方式
|
||||
*/
|
||||
@Test
|
||||
public void startConsistentSessionConsumer() {
|
||||
var context = new ClassPathXmlApplicationContext("provider/consumer_consistent_session_config.xml");
|
||||
public void startConsistentHashConsumer() {
|
||||
var context = new ClassPathXmlApplicationContext("provider/consumer_consistent_hash_config.xml");
|
||||
SessionUtils.printSessionInfo();
|
||||
|
||||
var ask = new ProviderMessAsk();
|
||||
@@ -126,4 +126,25 @@ public class ProviderTest {
|
||||
ThreadUtils.sleep(Long.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存的一致性hash算法消费方式
|
||||
*/
|
||||
@Test
|
||||
public void startCachedConsistentHashConsumer() {
|
||||
var context = new ClassPathXmlApplicationContext("provider/consumer_cached_consistent_config.xml");
|
||||
SessionUtils.printSessionInfo();
|
||||
|
||||
var ask = new ProviderMessAsk();
|
||||
ask.setMessage("Hello, this is the consumer!");
|
||||
var atomicInteger = new AtomicInteger(0);
|
||||
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
ThreadUtils.sleep(1000);
|
||||
NetContext.getConsumer().asyncAsk(ask, ProviderMessAnswer.class, 100).whenComplete(answer -> {
|
||||
logger.info("消费者请求[{}]收到消息[{}]", atomicInteger.incrementAndGet(), JsonUtils.object2String(answer));
|
||||
});
|
||||
}
|
||||
|
||||
ThreadUtils.sleep(Long.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
|
||||
xmlns:net="http://www.zfoo.com/schema/net"
|
||||
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-4.0.xsd
|
||||
|
||||
http://www.zfoo.com/schema/net
|
||||
http://www.zfoo.com/schema/net-1.0.xsd">
|
||||
|
||||
<context:property-placeholder location="classpath:deploy-dev.properties"/>
|
||||
|
||||
<context:component-scan base-package="com.zfoo"/>
|
||||
|
||||
<net:config id="applicationNameTest" protocol-location="protocol.xml">
|
||||
<net:registry center="${registry.center}" user="${registry.user}" password="${registry.password}">
|
||||
<net:address name="${registry.address.name}" url="${registry.address.url}"/>
|
||||
</net:registry>
|
||||
|
||||
<net:consumers>
|
||||
<net:consumer load-balancer="cached-consistent-hash" consumer="myProvider1"/>
|
||||
</net:consumers>
|
||||
</net:config>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user