新闻中心
新闻中心与新手教程
新闻中心与新手教程
发布时间:2024-10-12 11:56:37
conf/zoo_sample.cfg
为 zoo.cfg
zoo.cfg
,设置 datadir
和 clientport
bin/zkserver.sh start
application.properties
:dubbo.application.name=dubbo-provider
dubbo.registry.address=zookeeper://localhost:2181
dubbo.protocol.name=dubbo
dubbo.protocol.port=20880
public interface helloservice {
string sayhello(string name);
}
@dubboservice
public class helloserviceimpl implements helloservice {
@override
public string sayhello(string name) {
return "hello, " + name;
}
}
@configuration
@enabledubbo(scanbasepackages = "com.example.service")
@propertysource("classpath:/application.properties")
public class providerconfiguration {
}
public class providerapplication {
public static void main(string[] args) throws exception {
annotationconfigapplicationcontext context = new annotationconfigapplicationcontext(providerconfiguration.class);
context.start();
system.in.read();
}
}
application.properties
:dubbo.application.name=dubbo-consumer
dubbo.registry.address=zookeeper://localhost:2181
@configuration
@enabledubbo(scanbasepackages = "com.example.service")
@propertysource("classpath:/application.properties")
public class consumerconfiguration {
}
public class consumerapplication {
@dubboreference
private helloservice helloservice;
public static void main(string[] args) {
annotationconfigapplicationcontext context = new annotationconfigapplicationcontext(consumerconfiguration.class);
context.start();
consumerapplication application = context.getbean(consumerapplication.class);
string result = application.helloservice.sayhello("dubbo");
system.out.println("result: " + result);
}
}
dubbo.registry.address
配置是否正确ls /dubbo/com.example.service.helloservice/providers
dubbo.consumer.timeout=5000
dubbo.consumer.loadbalance=roundrobin
dubbo.protocol.serialization=hessian2
----------------------------------------------------------
上面是一个详细的 dubbo + zookeeper 服务发现最佳实践指南。这个指南涵盖了从环境准备到故障排查的全面内容。您可以按照这个指南逐步实施 dubbo 和 zookeeper 的集成。
主要内容包括:
这个指南应该能帮助您快速入门并解决可能遇到的常见问题。
感谢提供:05互联