当前位置: 首页>>代码示例>>Java>>正文


Java InstanceRegisteredEvent类代码示例

本文整理汇总了Java中org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent的典型用法代码示例。如果您正苦于以下问题:Java InstanceRegisteredEvent类的具体用法?Java InstanceRegisteredEvent怎么用?Java InstanceRegisteredEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InstanceRegisteredEvent类属于org.springframework.cloud.client.discovery.event包,在下文中一共展示了InstanceRegisteredEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteRoute

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@RequestMapping(path = "/_remove/{routeId}", method = RequestMethod.GET,
    produces = {MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XHTML_XML_VALUE})
public String deleteRoute(@PathVariable("routeId") String routeId,
    RedirectAttributes attributes) {

  zuulRouteRepository.findOneByRouteId(routeId).map(zuulRouteEntity -> {
    zuulRouteRepository.delete(zuulRouteEntity);
    addSuccessMessage(attributes, "路由 " + routeId + " 已删除。");
    publisher.publishEvent(new InstanceRegisteredEvent<>(this, this.environment));
    return zuulRouteEntity;
  }).orElseGet(() -> {
    addWarningMessage(attributes, "没有找到 " + routeId + " 路由。");
    return null;
  });
  return "redirect:/restRoute.html";
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:17,代码来源:RestRouteAdminController.java

示例2: start

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
public void start() {
	if (!isEnabled()) {
		if (logger.isDebugEnabled()) {
			logger.debug("Discovery Lifecycle disabled. Not starting");
		}
		return;
	}

	// only initialize if nonSecurePort is greater than 0 and it isn't already running
	// because of containerPortInitializer below
	if (!this.running.get()) {
		register();
		if (shouldRegisterManagement()) {
			registerManagement();
		}
		this.context.publishEvent(
				new InstanceRegisteredEvent<>(this, getConfiguration()));
		this.running.compareAndSet(false, true);
	}

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:22,代码来源:AbstractAutoServiceRegistration.java

示例3: start

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@Override
public void start() {
	// only set the port if the nonSecurePort or securePort is 0 and this.port != 0
	if (this.port.get() != 0) {
		if (this.registration.getNonSecurePort() == 0) {
			this.registration.setNonSecurePort(this.port.get());
		}

		if (this.registration.getSecurePort() == 0 && this.registration.isSecure()) {
			this.registration.setSecurePort(this.port.get());
		}
	}

	// only initialize if nonSecurePort is greater than 0 and it isn't already running
	// because of containerPortInitializer below
	if (!this.running.get() && this.registration.getNonSecurePort() > 0) {

		this.serviceRegistry.register(this.registration);

		this.context.publishEvent(
				new InstanceRegisteredEvent<>(this, this.registration.getInstanceConfig()));
		this.running.set(true);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:25,代码来源:EurekaAutoServiceRegistration.java

示例4: test_matching_and_ignore_pattern

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@Test
public void test_matching_and_ignore_pattern() {
    when(discovery.getServices()).thenReturn(asList("service-1", "service", "rabbit-1", "rabbit-2"));
    when(discovery.getInstances("service")).thenReturn(
            singletonList(new DefaultServiceInstance("service", "localhost", 80, false)));
    when(discovery.getInstances("service-1")).thenReturn(
            singletonList(new DefaultServiceInstance("service-1", "localhost", 80, false)));

    listener.setServices(singleton("ser*"));
    listener.setIgnoredServices(singleton("service-*"));
    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

    StepVerifier.create(registry.getInstances())
                .assertNext(a -> assertThat(a.getRegistration().getName()).isEqualTo("service"))
                .verifyComplete();
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:17,代码来源:InstanceDiscoveryListenerTest.java

示例5: test_register_and_convert

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@Test
public void test_register_and_convert() {
    when(discovery.getServices()).thenReturn(singletonList("service"));
    when(discovery.getInstances("service")).thenReturn(
            singletonList(new DefaultServiceInstance("service", "localhost", 80, false)));

    listener.onInstanceRegistered(new InstanceRegisteredEvent<>(new Object(), null));

    StepVerifier.create(registry.getInstances()).assertNext(application -> {
        Registration registration = application.getRegistration();
        assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:80/health");
        assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:80/");
        assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:80/");
        assertThat(registration.getName()).isEqualTo("service");
    }).verifyComplete();


}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:19,代码来源:InstanceDiscoveryListenerTest.java

示例6: registerInstance

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@Override
protected URI registerInstance() {
    //We register the instance by setting static values for the SimpleDiscoveryClient and issuing a
    //InstanceRegisteredEvent that makes sure the instance gets registered.
    SimpleDiscoveryProperties.SimpleServiceInstance serviceInstance = new SimpleDiscoveryProperties.SimpleServiceInstance();
    serviceInstance.setServiceId("Test-Instance");
    serviceInstance.setUri(URI.create("http://localhost:" + getPort()));
    serviceInstance.getMetadata().put("management.context-path", "/mgmt");
    simpleDiscovery.getInstances().put("Test-Application", singletonList(serviceInstance));

    instance.publishEvent(new InstanceRegisteredEvent<>(new Object(), null));

    //To get the location of the registered instances we fetch the instance with the name.
    List<JSONObject> applications = getWebClient().get()
                                                  .uri("/instances?name=Test-Instance")
                                                  .accept(MediaType.APPLICATION_JSON)
                                                  .exchange()
                                                  .expectStatus()
                                                  .isOk()
                                                  .returnResult(JSONObject.class)
                                                  .getResponseBody()
                                                  .collectList()
                                                  .block();
    assertThat(applications).hasSize(1);
    return URI.create("http://localhost:" + getPort() + "/instances/" + applications.get(0).optString("id"));
}
 
开发者ID:codecentric,项目名称:spring-boot-admin,代码行数:27,代码来源:AdminApplicationDiscoveryTest.java

示例7: deleteRoute

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@RequestMapping(path = "/_remove/{routeId}", method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE,
                                                                                      MediaType.APPLICATION_XHTML_XML_VALUE })
public String deleteRoute(@PathVariable("routeId") String routeId, RedirectAttributes attributes) {

    zuulRouteRepository.findOneByRouteId(routeId).map(zuulRouteEntity -> {
        zuulRouteRepository.delete(zuulRouteEntity);
        addSuccessMessage(attributes, "路由 " + routeId + " 已删除。");
        publisher.publishEvent(new InstanceRegisteredEvent<>(this, this.environment));
        return zuulRouteEntity;
    }).orElseGet(() -> {
        addWarningMessage(attributes, "没有找到 " + routeId + " 路由。");
        return null;
    });
    return "redirect:/grpcRoute.html";
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:16,代码来源:GrpcRouteAdminController.java

示例8: create

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@RequestMapping(path = "/_create", method = RequestMethod.POST,
    consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
    produces = {MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XHTML_XML_VALUE})
public String create(@RequestParam(name = "routeId", required = true) String routeId,
    @RequestParam(name = "routePath", required = true) String routePath,
    @RequestParam(name = "routeUrl", required = true) String routeUrl,
    @RequestParam(name = "serviceId", required = true) String serviceId,
    @RequestParam(name = "stripPrefix", defaultValue = "false") Boolean stripPrefix,
    @RequestParam(name = "retryAble", defaultValue = "false") Boolean retryAble,
    @RequestParam(name = "sensitiveHeaders", defaultValue = "") String sensitiveHeaders,
    RedirectAttributes attributes) {
  if (zuulRouteRepository.findOneByRouteId(routeId).isPresent()) {
    addErrorMessage(attributes, routeId + "已经存在 ");
    resetRequestParams(routeId, routePath, routeUrl, serviceId, stripPrefix, retryAble,
        sensitiveHeaders, attributes);
    return "redirect:/restRoute.html?type=add";
  }
  ZuulRouteEntity entityRest = ZuulRouteEntity.builder()//
      .zuul_route_id(routeId)//
      .path(routePath)//
      .strip_prefix(stripPrefix)//
      .retryable(retryAble)//
      .url(routeUrl)//
      .service_id(serviceId)//
      .sensitiveHeaders(sensitiveHeaders)//
      .build();
  zuulRouteRepository.save(entityRest);
  publisher.publishEvent(new InstanceRegisteredEvent<>(this, this.environment));
  return "redirect:/restRoute.html";
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:31,代码来源:RestRouteAdminController.java

示例9: update

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@RequestMapping(path = "/_update", method = RequestMethod.POST,
    consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
    produces = {MediaType.TEXT_HTML_VALUE, MediaType.APPLICATION_XHTML_XML_VALUE})
public String update(@RequestParam(name = "routeId", required = true) String routeId,
    @RequestParam(name = "routePath", required = true) String routePath,
    @RequestParam(name = "routeUrl", required = true) String routeUrl,
    @RequestParam(name = "serviceId", required = true) String serviceId,
    @RequestParam(name = "stripPrefix", defaultValue = "false") Boolean stripPrefix,
    @RequestParam(name = "retryAble", defaultValue = "false") Boolean retryAble,
    @RequestParam(name = "sensitiveHeaders", defaultValue = "") String sensitiveHeaders,
    RedirectAttributes attributes) {

  zuulRouteRepository.findOneByRouteId(routeId).map(zuulRouteEntity -> {
    zuulRouteEntity.setZuul_route_id(routeId);
    zuulRouteEntity.setPath(routePath);
    zuulRouteEntity.setUrl(routeUrl);
    zuulRouteEntity.setService_id(serviceId);
    zuulRouteEntity.setStrip_prefix(stripPrefix);
    zuulRouteEntity.setRetryable(retryAble);
    zuulRouteEntity.setSensitiveHeaders(sensitiveHeaders);
    return zuulRouteRepository.save(zuulRouteEntity);
  }).orElseGet(() -> {
    addErrorMessage(attributes, "routeId" + routeId + " 不存在。");
    return null;
  });
  publisher.publishEvent(new InstanceRegisteredEvent<>(this, this.environment));
  return "redirect:/restRoute.html";
}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:29,代码来源:RestRouteAdminController.java

示例10: save

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@RequestMapping(value = "/", method = RequestMethod.POST)
public void save(@RequestBody Document document) throws Exception {
    Swagger swagger = new SwaggerParser()
            .read(document.getUrl());
    String content = objectMapper.writeValueAsString(swagger);
    if(StringUtils.isBlank(document.getTitle())){
        document.setTitle(swagger.getInfo().getTitle());
    }
    documentService.save(document.setContent(content));
    applicationEventPublisher.publishEvent(new InstanceRegisteredEvent<>(SwaggerDocDiscovery.class, swagger));
}
 
开发者ID:wu191287278,项目名称:sc-generator,代码行数:12,代码来源:DocumentController.java

示例11: upload

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void upload(MultipartFile file, HttpServletResponse response) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copy(file.getInputStream(), out);
    Swagger swagger = new SwaggerParser()
            .parse(out.toString("utf-8"));
    out.close();
    String content = objectMapper.writeValueAsString(swagger);
    documentService.save(new Document()
            .setContent(content)
            .setTitle(file.getOriginalFilename()));
    applicationEventPublisher.publishEvent(new InstanceRegisteredEvent<>(SwaggerDocDiscovery.class, swagger));
    response.sendRedirect("/#/document.html");
}
 
开发者ID:wu191287278,项目名称:sc-generator,代码行数:15,代码来源:DocumentController.java

示例12: start

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@Override
public void start() {
    if (!isEnabled()) {
        return;
    }
    if (running.compareAndSet(false, true)) {
        register();
        getContext().publishEvent(new InstanceRegisteredEvent<>(this,
                getConfiguration()));
    }
}
 
开发者ID:fabric8io,项目名称:spring-cloud-kubernetes,代码行数:12,代码来源:KubernetesDiscoveryLifecycle.java

示例13: onApplicationEvent

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(InstanceRegisteredEvent<?> event) {
	this.cache = TreeCache.newBuilder(this.curator, this.properties.getRoot()).build();
	this.cache.getListenable().addListener(this);
	try {
		this.cache.start();
	}
	catch (Exception e) {
		ReflectionUtils.rethrowRuntimeException(e);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-zookeeper,代码行数:12,代码来源:ZookeeperServiceWatch.java

示例14: testHealthIndicatorDescriptionDisabled

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@Test
public void testHealthIndicatorDescriptionDisabled() {
	assertNotNull("healthIndicator was null", this.healthIndicator);
	Health health = this.healthIndicator.health();
	assertHealth(health, Status.UNKNOWN);

	clientHealthIndicator.onApplicationEvent(new InstanceRegisteredEvent<>(this, null));

	health = this.healthIndicator.health();
	Status status = assertHealth(health, Status.UP);
	assertEquals("status description was wrong", "TestDiscoveryClient",
			status.getDescription());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:14,代码来源:DiscoveryClientHealthIndicatorTests.java

示例15: testHealthIndicator

import org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent; //导入依赖的package包/类
@Test
public void testHealthIndicator() {
	assertNotNull("healthIndicator was null", this.healthIndicator);
	Health health = this.healthIndicator.health();
	assertHealth(health, Status.UNKNOWN);

	clientHealthIndicator.onApplicationEvent(new InstanceRegisteredEvent<>(this, null));

	health = this.healthIndicator.health();
	Status status = assertHealth(health, Status.UP);
	assertEquals("status description was wrong", "",
			status.getDescription());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:14,代码来源:DiscoveryCompositeHealthIndicatorTests.java


注:本文中的org.springframework.cloud.client.discovery.event.InstanceRegisteredEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。