springcloud + zookeeper architecture building

zookeeper Baidu own installation configuration.

zookeeper visualization tools zkui Baidu own configuration.

 

springcloud micro Services Architecture greatest feature is restful, he let the communication between the service through the micro restful achieve, write micro-services as writing a normal controller as simple. When you want to the outside world is to provide a service, but a simple interface to expose a restful, and the development of traditional SpringMVC basically no difference, greatly reduce learning costs, so this architecture easier to understand. At the same time now springcloud support feign, when the need to consume the service only need to write in a local interface with notes marked micro service providers need to access, and then just like regular access to a restful interface to access as a micro service.

 

Configuration:

You need to start following module micro services, and establish bootstrap.yml application.yml same level directory, can be said to be a dedicated configuration springboot application.yml project, and bootstrap.yml is springcloud + zookeeper special configuration, the bootstrap.yml boot priority is better than application.yml of.

the Spring: 
the Application:
name: Goods # micro-Service Service Name
Cloud:
ZooKeeper:
Connect-String: 192.168.2.157:2181 #zookeeper server addresses into your own
Discovery:
Enabled: whether to true # Enable ZooKeeper
the Register: whether to true # Sign up micro-services


these are the contents of bootstrap.yml.

Micro service provider configuration:
starting classes plus @EnableDiscoveryClient on the line, not something else
@RestController
public class HelloMS {
@GetMapping("/ms/hello/{id}")
public String hello(@PathVariable long id){
return String.valueOf(id);
}
}
 
@FeignClient (value = "Hello-MS") 
public interface HelloFeign {

@GetMapping ( " / MS / Hello / {ID} ")
String the getHello ( @PathVariable ; Long ID)
}



when defined the following classes of consumers, the need to use @Autowired just one click away
 
@EnableFeignClients("com.yongbang.b2b.server")
@EnableDiscoveryClient
@SpringBootApplication
public class Bootstrap {

public static void main(String[] args) {
SpringApplication.run(Bootstrap.class, args);
}

}

Guess you like

Origin www.cnblogs.com/nocyan/p/11655960.html