Java Code Examples for org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration

The following examples show how to use org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private String getManagementUrl(EurekaRegistration registration) {
    String sslKey = "server.ssl.enabled";
    String portKey = "server.port";
    String pathKey = "server.servlet.context-path";
    String managementKey = "management.";
    String endpointPathKey = "management.endpoints.web.base-path";
    if (environment.containsProperty(managementKey + portKey)) {
        sslKey = managementKey + sslKey;
        portKey = managementKey + portKey;
        pathKey = managementKey + pathKey;
    }
    Boolean isHttps = environment.getProperty(sslKey, Boolean.class, Boolean.FALSE);
    String port = environment.getProperty(portKey, "");
    String contextPath = environment.getProperty(pathKey, "/");
    String scheme = isHttps ? "https" : "http";
    String uri = String.format("%s://%s:%s", scheme, registration.getHost(),
        StringUtils.isEmpty(port) ? registration.getPort() : port);
    uri = uri + contextPath;
    uri = uri + environment.getProperty(endpointPathKey, "/actuator");
    return uri;
}
 
Example 2
@Override
public void register(EurekaRegistration registration) {
    String group = this.getProperties(Constants.PROVIDER_INSTANCE_GROUP);
    String version = this.getProperties(Constants.PROVIDER_INSTANCE_VERSION);
    if (group != null && version != null) {
        registration.getMetadata().put(Constants.EUREKA_METADATA_GROUP, group);
        registration.getMetadata().put(Constants.EUREKA_METADATA_VERSION, version);
    }
    String springfoxEnable = this.getProperties(Constants.PROVIDER_SPRINGFOX_ENABLE);
    if ("true".equals(springfoxEnable)) {
        registration.getMetadata().put(Constants.EUREKA_METADATA_SPRINGFOX, springfoxEnable);
    }
    registration.getMetadata().put(Constants.EUREKA_METADATA_MANAGEMENT_URL, getManagementUrl(registration));
    serviceRegistry.register(registration);
    new ScheduleReportServerLoad(registration).start();
}
 
Example 3
@RequestMapping(path = "/register", method = POST)
public String register() {
	EurekaInstanceConfigBean config = new EurekaInstanceConfigBean(inetUtils);
	String appname = "customapp";
	config.setIpAddress("127.0.0.1");
	config.setHostname("localhost");
	config.setAppname(appname);
	config.setVirtualHostName(appname);
	config.setSecureVirtualHostName(appname);
	config.setNonSecurePort(4444);
	config.setInstanceId("127.0.0.1:customapp:4444");

	this.registration = EurekaRegistration.builder(config)
			.with(this.clientConfig, this.context).build();

	this.serviceRegistry.register(this.registration);
	return config.getInstanceId();
}
 
Example 4
Source Project: Moss   Source File: MultRegisterCenterServerMgmtConfig.java    License: Apache License 2.0 5 votes vote down vote up
public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient,
                                             CloudEurekaInstanceConfig instanceConfig,
                                             ApplicationInfoManager applicationInfoManager,
                                             @Autowired(required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) {
    return EurekaRegistration.builder(instanceConfig)
            .with(applicationInfoManager)
            .with(eurekaClient)
            .with(healthCheckHandler)
            .build();
}
 
Example 5
Source Project: Moss   Source File: MultRegisterCenterServerMgmtConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 动态添加一个注册中心
 *
 * @param registerCenterCode
 * @param registerCenterUrl
 */
public void addEureka(String registerCenterCode, String registerCenterUrl) {

    ManagementMetadataProvider managementMetadataProvider = serviceManagementMetadataProvider();
    EurekaClientConfigBean configBean = eurekaClientConfigBean(env);
    configBean.getServiceUrl().clear();
    configBean.getServiceUrl().put(EurekaClientConfigBean.DEFAULT_ZONE, registerCenterUrl);
    EurekaInstanceConfigBean instanceConfigBean = eurekaInstanceConfigBean(inetUtils, env, managementMetadataProvider);
    instanceConfigBean.setEnvironment(env);
    instanceConfigBean.setAppname(instanceConfigBean.getAppname());
    ApplicationInfoManager manager = eurekaApplicationInfoManager(instanceConfigBean);


    /**
     * 添加EurekaClient,如果有就先删除,再添加
     */
    Map<String, EurekaClient> multEurekaMap = multRegisterCenter.getMultEurekaMap();
    revomeEurekaClientByCode(registerCenterCode);
    EurekaClient eurekaClient = eurekaClient(manager, configBean);
    multEurekaMap.put(registerCenterCode, eurekaClient);
    multRegisterCenter.getMultEurekaCodeMap().put(eurekaClient, registerCenterCode);

    /**
     * 添加autoServiceRegistration,如果有就先删除,再添加
     */
    Map<String, MossEurekaAutoServiceRegistration> multRegistrationMap = multRegisterCenter.getMultRegistrationMap();
    revomeServiceRegistration(registerCenterCode);
    EurekaRegistration registration = eurekaRegistration(eurekaClient, instanceConfigBean, manager, healthCheckHandler);
    MossEurekaAutoServiceRegistration autoServiceRegistration = eurekaAutoServiceRegistration(context, eurekaServiceRegistry(), registration, registration);
    autoServiceRegistration.start();
    multRegistrationMap.put(registerCenterCode, autoServiceRegistration);

    /**
     * 添加 HeartbeatMonitor
     */
    Map<EurekaClient, HeartbeatMonitor> multHeartbeatMonitorMap = multRegisterCenter.getMultHeartbeatMonitorMap();
    multHeartbeatMonitorMap.remove(registerCenterCode);
    multHeartbeatMonitorMap.put(eurekaClient, new HeartbeatMonitor());

}
 
Example 6
@Bean
public GrayServerFilter grayServerFilter(final EurekaRegistration registration) {

    registration.getMetadata().put(METADATA_GRAY_ENABLE, METADATA_GRAY_ENABLE_TRUE);
    String bkjkgrayToUse = StringUtils.isEmpty(bkjkgray) ? System.getProperty(BKJKGRAY) : bkjkgray;
    if (!StringUtils.isEmpty(bkjkgrayToUse)) {
        registration.getMetadata().put(BKJKGRAY, bkjkgrayToUse);
    }
    return new GrayServerFilter();
}
 
Example 7
@EventListener(ServiceInstancePreRegisteredEvent.class)
public void onServiceInstancePreRegistered(
		ServiceInstancePreRegisteredEvent event) {
	Registration registration = event.getSource();
	EurekaRegistration eurekaRegistration = EurekaRegistration.class
			.cast(registration);
	InstanceInfo instanceInfo = eurekaRegistration.getApplicationInfoManager()
			.getInfo();
	attachDubboMetadataServiceMetadata(instanceInfo.getMetadata());
}
 
Example 8
@Bean(initMethod = "registerStubs")
public StubsRegistrar stubsRegistrar(StubRunning stubRunning,
		ServiceRegistry<EurekaRegistration> serviceRegistry,
		ApplicationContext context, StubMapperProperties stubMapperProperties,
		InetUtils inetUtils, EurekaInstanceConfigBean eurekaInstanceConfigBean,
		EurekaClientConfigBean eurekaClientConfigBean) {
	return new EurekaStubsRegistrar(stubRunning, serviceRegistry,
			stubMapperProperties, inetUtils, eurekaInstanceConfigBean,
			eurekaClientConfigBean, context);
}
 
Example 9
public EurekaStubsRegistrar(StubRunning stubRunning,
		ServiceRegistry<EurekaRegistration> serviceRegistry,
		StubMapperProperties stubMapperProperties, InetUtils inetUtils,
		EurekaInstanceConfigBean eurekaInstanceConfigBean,
		EurekaClientConfigBean eurekaClientConfigBean, ApplicationContext context) {
	this.stubRunning = stubRunning;
	this.stubMapperProperties = stubMapperProperties;
	this.serviceRegistry = serviceRegistry;
	this.inetUtils = inetUtils;
	this.eurekaInstanceConfigBean = eurekaInstanceConfigBean;
	this.eurekaClientConfigBean = eurekaClientConfigBean;
	this.context = context;
}
 
Example 10
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
@ConditionalOnProperty(
		value = "spring.cloud.service-registry.auto-registration.enabled",
		matchIfMissing = true)
public EurekaAutoServiceRegistration eurekaAutoServiceRegistration(
		ApplicationContext context, EurekaServiceRegistry registry,
		EurekaRegistration registration) {
	return new EurekaAutoServiceRegistration(context, registry, registration);
}
 
Example 11
@Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
@ConditionalOnProperty(
		value = "spring.cloud.service-registry.auto-registration.enabled",
		matchIfMissing = true)
public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient,
		CloudEurekaInstanceConfig instanceConfig,
		ApplicationInfoManager applicationInfoManager, @Autowired(
				required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) {
	return EurekaRegistration.builder(instanceConfig).with(applicationInfoManager)
			.with(eurekaClient).with(healthCheckHandler).build();
}
 
Example 12
@Bean
@org.springframework.cloud.context.config.annotation.RefreshScope
@ConditionalOnBean(AutoServiceRegistrationProperties.class)
@ConditionalOnProperty(
		value = "spring.cloud.service-registry.auto-registration.enabled",
		matchIfMissing = true)
public EurekaRegistration eurekaRegistration(EurekaClient eurekaClient,
		CloudEurekaInstanceConfig instanceConfig,
		ApplicationInfoManager applicationInfoManager, @Autowired(
				required = false) ObjectProvider<HealthCheckHandler> healthCheckHandler) {
	return EurekaRegistration.builder(instanceConfig).with(applicationInfoManager)
			.with(eurekaClient).with(healthCheckHandler).build();
}
 
Example 13
Source Project: Moss   Source File: MossEurekaAutoServiceRegistration.java    License: Apache License 2.0 4 votes vote down vote up
public MossEurekaAutoServiceRegistration(ApplicationContext context, EurekaServiceRegistry serviceRegistry, EurekaRegistration registration, EurekaRegistration registration1) {
    super(context, serviceRegistry, registration);
    this.registration = registration1;
}
 
Example 14
Source Project: Moss   Source File: MossEurekaAutoServiceRegistration.java    License: Apache License 2.0 4 votes vote down vote up
public EurekaRegistration getRegistration() {
    return registration;
}
 
Example 15
Source Project: Moss   Source File: MossEurekaAutoServiceRegistration.java    License: Apache License 2.0 4 votes vote down vote up
public void setRegistration(EurekaRegistration registration) {
    this.registration = registration;
}
 
Example 16
Source Project: Moss   Source File: MossServerDiscoveryAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public MultRegisterCenter initMultEureka(MultRegisterCenterService multRegisterCenterService,
                                         MultRegisterCenterServerMgmtConfig mgmtConfig) {
    Map<String, String> URL_MAP;
    MultRegisterCenter multRegisterCenter;
    log.info("start init MultRegisterCenter");
    URL_MAP = multRegisterCenterService.getRegisterCenterList();
    if (URL_MAP.isEmpty()) {
        multRegisterCenter = new MultRegisterCenter(new ConcurrentHashMap<String, EurekaClient>(),
                new ConcurrentHashMap<String, MossEurekaAutoServiceRegistration>(),
                new ConcurrentHashMap<EurekaClient, HeartbeatMonitor>());
        return multRegisterCenter;
    }
    Map<String, EurekaClient> multEurekaMap = Maps.newConcurrentMap();
    Map<String, MossEurekaAutoServiceRegistration> multRegistrationMap = Maps.newConcurrentMap();
    Map<EurekaClient, HeartbeatMonitor> multHeartbeatMonitorMap = new ConcurrentHashMap<EurekaClient, HeartbeatMonitor>();
    URL_MAP.entrySet().forEach(e -> {
        log.info("start init eureka server:{}", e.getKey() + "-" + e.getValue());
        ManagementMetadataProvider managementMetadataProvider
                = mgmtConfig.serviceManagementMetadataProvider();
        EurekaClientConfigBean configBean
                = mgmtConfig.eurekaClientConfigBean(env);
        configBean.getServiceUrl().clear();
        configBean.getServiceUrl().put(EurekaClientConfigBean.DEFAULT_ZONE, e.getValue());
        EurekaInstanceConfigBean instanceConfigBean
                = mgmtConfig.eurekaInstanceConfigBean(inetUtils, env, managementMetadataProvider);
        instanceConfigBean.setEnvironment(env);
        ApplicationInfoManager manager
                = mgmtConfig.eurekaApplicationInfoManager(instanceConfigBean);
        EurekaClient eurekaClient
                = mgmtConfig.eurekaClient(manager, configBean);
        EurekaRegistration registration
                = mgmtConfig.eurekaRegistration(eurekaClient, instanceConfigBean, manager, healthCheckHandler);
        MossEurekaAutoServiceRegistration autoServiceRegistration
                = mgmtConfig.eurekaAutoServiceRegistration(context, mgmtConfig.eurekaServiceRegistry(), registration, registration);
        multEurekaMap.put(e.getKey(), eurekaClient);
        multRegistrationMap.put(e.getKey(), autoServiceRegistration);
        multHeartbeatMonitorMap.put(eurekaClient, new HeartbeatMonitor());
        log.info("init eureka server:{} end!", e.getKey() + "-" + e.getValue());
    });
    multRegisterCenter = new MultRegisterCenter(multEurekaMap, multRegistrationMap, multHeartbeatMonitorMap);
    log.info("init MultRegisterCenter End!");
    return multRegisterCenter;
}
 
Example 17
Source Project: Moss   Source File: MultRegisterCenterServerMgmtConfig.java    License: Apache License 2.0 4 votes vote down vote up
public MossEurekaAutoServiceRegistration eurekaAutoServiceRegistration(ApplicationContext context, EurekaServiceRegistry registry,
                                                                       EurekaRegistration registration, EurekaRegistration registration1) {
    return new MossEurekaAutoServiceRegistration(context, registry, registration, registration1);
}
 
Example 18
public HttpClientGrayHeaderCustomizer(EurekaRegistration registration, GrayRulesStore grayRulesStore) {
    super(registration, grayRulesStore);
}
 
Example 19
Source Project: summerframework   Source File: GrayAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public HttpClientGrayHeaderCustomizer httpClientGrayHeaderCustomizer(EurekaRegistration registration) {
    return new HttpClientGrayHeaderCustomizer(registration, grayRulesStore);
}
 
Example 20
Source Project: summerframework   Source File: GrayAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public OpenFeignGrayHeaderCustomizer openFeignGrayHeaderCustomizer(EurekaRegistration registration) {
    return new OpenFeignGrayHeaderCustomizer(registration, grayRulesStore);
}
 
Example 21
Source Project: summerframework   Source File: GrayAutoConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public RestTemplateGrayHeaderCustomizer restTemplateGrayHeaderCustomizer(EurekaRegistration registration) {
    return new RestTemplateGrayHeaderCustomizer(registration, grayRulesStore);
}
 
Example 22
public AbstractGrayHeaderCustomizer(EurekaRegistration registration, GrayRulesStore grayRulesStore) {
    this.registration = registration;
    this.grayRulesStore = grayRulesStore;
}
 
Example 23
public OpenFeignGrayHeaderCustomizer(EurekaRegistration registration, GrayRulesStore grayRulesStore) {
    super(registration, grayRulesStore);
}
 
Example 24
public RestTemplateGrayHeaderCustomizer(EurekaRegistration registration, GrayRulesStore grayRulesStore) {
    super(registration, grayRulesStore);
}
 
Example 25
Source Project: summerframework   Source File: ScheduleReportServerLoad.java    License: Apache License 2.0 4 votes vote down vote up
public ScheduleReportServerLoad(EurekaRegistration registration) {
    this.registration = registration;
}
 
Example 26
public EurekaServiceRegistryWrapper(ServiceRegistry<EurekaRegistration> serviceRegistry,
    ConfigurableEnvironment environment) {
    this.serviceRegistry = serviceRegistry;
    this.environment = environment;
}
 
Example 27
@Override
public void deregister(EurekaRegistration registration) {
    serviceRegistry.deregister(registration);
}
 
Example 28
@Override
public Object getStatus(EurekaRegistration registration) {
    return serviceRegistry.getStatus(registration);
}
 
Example 29
@Override
public void setStatus(EurekaRegistration registration, String status) {
    serviceRegistry.setStatus(registration, status);
}
 
Example 30
@Override
public void afterPropertiesSet() throws Exception {
    eurekaServiceRegistry = applicationContext.getBean(EurekaServiceRegistry.class);
    eurekaRegistration = applicationContext.getBean(EurekaRegistration.class);
}