Home > Archives > 微服务:Eureka和Discovery Client

微服务:Eureka和Discovery Client

Publish:

@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication {

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

}
server.port=1111
eureka.client.register-with-eureka=false 
eureka.client.fetch-registry=false 
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka

@EnableDiscoveryClient
@SpringBootApplication
public class ComputeApplication {

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

}

spring.application.name=compute-service
server.port=2223
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ComputeController {
    Logger logger = LoggerFactory.getLogger(ComputeController.class);
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public Integer add(@RequestParam Integer a, @RequestParam Integer b) {
        Integer r = a + b;
        logger.info("/add,  result:" + r);
        return r;
    }
}

参考

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo