The properties configurations of the provider and consumer are similar.
The value of Nutz. application. Name is different.
Server. Port = 0
The consumer generally needs to provide external web services with the IP address and port server. Port = 8088 server. Host = 0.0.0.0
Service provider application. Properties
server.port=0nutz.application.name=serverdubbo.registry.address=zookeeper://127.0.0.1:2181dubbo.protocol.name=dubbodubbo.protocol.port=0dubbo.annotation.package=com.chao.dubbo.rpc
Service consumer
server.port=8088server.host=0.0.0.0nutz.application.name=clientdubbo.registry.address=zookeeper://127.0.0.1:2181dubbo.protocol.name=dubbodubbo.protocol.port=0dubbo.annotation.package=com.chao.dubbo.rpc
Add dependency
<! -- Core dependency of nutzboot --> <dependency> <groupid> Org. </groupid> <artifactid> nutzboot-core </artifactid> <version> 2.3-Snapshot </version> </dependency> <! -- Log related --> <dependency> <groupid> org. slf4j </groupid> <artifactid> slf4j-log4j12 </artifactid> <version> 1.7.25 </version> </dependency> <! -- Dubbo dependency --> <dependency> <groupid> Org. </groupid> <artifactid> nutzboot-starter-Dubbo </artifactid> <version> 2.3-Snapshot </version> </dependency> <! -- Interface project dependency --> <dependency> <groupid> COM. chao. test </groupid> <artifactid> Dubbo-common </artifactid> <version >$ {project. version }</version> </dependency> <! -- Zookeeper client dependence --> <dependency> <groupid> com.101tec </groupid> <artifactid> zkclient </artifactid> <version> 0.11 </version> </dependency> <! -- Do not add the following dependent service providers. service consumers use the Web Services provided externally --> <dependency> <groupid> org. </groupid> <artifactid> nutzboot-starter-nutz-MVC </artifactid> <version >$ {nutzboot. version }</version> </dependency> <groupid> Org. </groupid> <artifactid> nutzboot-starter-jetty </artifactid> <version >$ {nutzboot. version} </version> </dependency>
Interface project (Dubbo-commonThere is nothing in an interface class)
public interface TimeService { long now();}
Service provider Project (Dubbo-server)
@IocBean@Service(interfaceClass = TimeService.class)public class TimeServiceImpl implements TimeService { public long now() { return System.currentTimeMillis(); }}
Startup class
@IocBeanpublic class ServiceLauncher { public static void main(String[] args) throws Exception{ new NbApp().run(); }}
Service consumer Project (Dubbo-client)
@ Iocbeanpublic class clientlauncher {// inject remote service @ inject @ reference private timeservice; // Use http: // localhost: 8088/now call test @ at @ OK ("Raw") public Long Now () {return timeservice. now ();} public static void main (string [] ARGs) throws exception {New nbapp (). run ();}}
Do not forget to start the zookeeper Client
(WIN) zkserver. CMD (Linux) zkserver. Sh
Simple use of nutzboot Dubbo zookeeper