Eureka use

 

 eureka registry server: 

Server: 
  Port: 8761 
Eureka: 
  Client: 
    # Since the application for the registry, it is set to false, the representative does not register itself to the registry 
    registerWithEureka: false 
    # Since the registry duties is to maintain a service instance, it does not need to retrieve the service , so it is set to false 
    fetchRegistry: false 
    serviceUrl: 
      defaultzone: HTTP: // localhost: 8761 / Eureka /

 

clientA initiate registration

Server: 
  Port: 8001 
# client service discovery 
Eureka: 
  instance: 
    # when registering to Eureka, whether to use IP address + port number that uniquely identifies a service instance. Recommended set to true 
    the prefer -ip-address: to true 
  Client: 
    # whether to register their information to the Eureka server instance 
    the Register the -with-Eureka: to true 
    # Whether to pull cache and other services to the local copy of the registry 
    FETCH -registry: to true 
    # eureka client cache refresh local time 
    registryFetchIntervalSeconds: 5 
    # registered service instance to which Eureka 
    service - url: 
      defaultzone: HTTP: // localhost: 8761 / Eureka /

 

clientB initiate registration

Server: 
  Port: 8002 
# client service discovery 
Eureka: 
  instance: 
    # when registering to Eureka, whether to use IP address + port number that uniquely identifies a service instance. Recommended set to true 
    the prefer -ip-address: to true 

  Client: 
    # whether to register their information to the Eureka server instance 
    the Register the -with-Eureka: to true 
    # Whether to pull cache and other services to the local copy of the registry 
    FETCH -registry: to true 
    # eureka client cache refresh local time 
    registryFetchIntervalSeconds: 5 
    # registered service instance to which Eureka 
    service - url: 
      defaultzone: HTTP: // localhost: 8761 / Eureka /      
      

 

 

 

eureka service call: clientA call clientB interface

@FeignClient("ueh-organization")
public interface OrganizationClient {
    @GetMapping("/organization/{organizationId}")
    R<OrganizationDTO> getOrganization(@PathVariable("organizationId") Long organizationId);
}    
{
    @Autowired
    private OrganizationClient organizationClient; 

    public LicenceDTO queryDetail(Long licenceId) {
        Licence licence = this.getById(licenceId);
        // 校验非空
        ResponseEnum.LICENCE_NOT_FOUND.assertNotNull(licence);

        OrganizationDTO org = ClientUtil.execute(() -> organizationClient.getOrganization(licence.getOrganizationId()));
        return toLicenceDTO(licence, org);
    }
}
// remote call tools 
public  class ClientUtil {
     / ** 
     * package remote call returns only the content of interest 
     * @param Supplier true logic remote call, returns contents: { @link R & lt <T>} 
     * @param <T> the content type of interest 
     * @return another message
      * / 
    public  static <T> T Execute (Supplier <R & lt <T >> Supplier) { 
        R & lt <T> = R & lt supplier.get (); 
        CommonResponseEnum.assertSuccess (R & lt); 
        return r.getData (); 
    } 

    / ** 
     * package remote call returns only the content of interest 
     * @param Supplier true logic procedure call, returns contents: {@link the QR <T>} 
     * @param <T> content type of interest 
     * @return another message
      * / 
    public  static <T> QueryData is <T> executePage (Supplier <the QR <T >> Supplier) { 
        the QR <T> = QR supplier.get (); 
        CommonResponseEnum.assertSuccess (QR); 
        return qr.getData (); 
    } 
}

 

 

clientB端Controller

@RequestMapping("/organization")
@RestController
public class OrganizationController {
    @Autowired
    private OrganizationService organizationService;
    @GetMapping("/{organizationId}")
    public R<OrganizationDTO> getOrganization(@PathVariable("organizationId") Long organizationId) {
        return new R<>(organizationService.queryDetail(organizationId));
    }
}

 

Guess you like

Origin www.cnblogs.com/hahajava/p/11308561.html