blog.csdn.net/weixin\_495…

A distributed system is a system composed of a group of computer nodes that communicate through a network and coordinate their work to accomplish a common task. The emergence of distributed systems is to use cheap, ordinary machines to complete a single computer can not complete the computation, storage tasks. The aim is to use more machines to process more data.

A distributed system is a software system built on a network.

1. Environmental

  • Dubbo installation
  • They are installed

2. Frame building

Pom depends on

  • Dubbo

    Org. Apache. Dubbo dubbo – spring – the boot – starter 2.7.3. 123456

  • zookeeper

    Com. Making. Sgroschupf zkclient 0.1 123456

  • To resolve log conflicts, you need to remove log dependencies from ZooKeeper and its dependent packages

    Org.apache. curator curator- Framework 2.12.0 org.apache.curator Curator – Recipes 2.12.0 org.apache. zooKeeper Zookeeper 3.4.14 org. Slf4j slf4j log4j12-1234567891011121314151617181920212223

Provider (provider- Server)

  • Configure dubbo properties in the Springboot configuration file

    # configuration dubbo dubbo. Application. Name = the product – the address of the server # registry dubbo. Registry. Address = zookeeper: / / 127.0.0.1:2181 # registered service dubbo.scan.base-packages=com.lit.Service 123456

  • Configure service annotations in the service implementation class and publish the service! Pay attention to the packet guide problem

    package com.lit.Service;

    public interface TicketService { public String getTicket(); } 12345

    package com.lit.Service; import org.springframework.stereotype.Service; / / the zookeeper Service registration and discovery @ Service @ com. Alibaba. Dubbo. Config. The annotation. The Service public class TicketServiceImpl implements TicketService {@override public String getTicket() {return “Got a Ticket “; }} 1234567891011

Service Consumers

  • Configuration parameters

    # current application name dubbo. Application. Name = consumer – # server registry address dubbo. Registry. Address = zookeeper: / / 127.0.0.1:2181 1234

  • Take the interface of the service directly, and the path must be correct, that is, the same as the service provider

    package com.lit.Service;

    public interface TicketService { public String getTicket(); } 12345

  • Consumer Services

    package com.lit.Service;

    import org.apache.dubbo.config.annotation.Reference; import org.springframework.stereotype.Service;

    @reference // Reference the remote Pom coordinates: you can define the same interface name TicketService TicketService;

    public void buyTicket(){ String ticket = ticketService.getTicket(); System. The out. Println (" in the registry to -- -- -- -- -- -- -- -- -- > "+ ticket); }Copy the code

    }

    1234567891011121314151617

3. Test class writing

@SpringBootTest class ConsumerApplicationTests { @Autowired ConsumerService consumerService; @Test void contextLoads() { consumerService.buyTicket(); }} 12345678910Copy the code

Start the test

  • Open the zookeeper
  • Open dubo-admin for monitoring
  • Service starter
  • Consumer consumption test