Simple use of nutzboot Dubbo zookeeper

Source: Internet
Author: User
Tags zookeeper client

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.