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

The following examples show how to use org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration. 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
Source File: EurekaSampleApplication.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: EurekaServiceRegistryWrapper.java    From summerframework with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: EurekaServiceRegistryWrapper.java    From summerframework with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: EurekaClientAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@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 #5
Source File: EurekaClientAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: MultRegisterCenterServerMgmtConfig.java    From Moss with 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 #7
Source File: MultRegisterCenterServerMgmtConfig.java    From Moss with 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 #8
Source File: EurekaStubsRegistrar.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
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 #9
Source File: StubRunnerSpringCloudEurekaAutoConfiguration.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: DubboServiceRegistrationAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@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 #11
Source File: EurekaClientAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: GrayFilterAutoConfiguration.java    From summerframework with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: EurekaStubsRegistrar.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	for (EurekaRegistration registration : this.registrations) {
		this.serviceRegistry.deregister(registration);
	}
}
 
Example #14
Source File: EurekaInstanceDiscoveryClient.java    From spring-cloud-gray with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    eurekaServiceRegistry = applicationContext.getBean(EurekaServiceRegistry.class);
    eurekaRegistration = applicationContext.getBean(EurekaRegistration.class);
}
 
Example #15
Source File: EurekaServiceRegistryWrapper.java    From summerframework with Apache License 2.0 4 votes vote down vote up
@Override
public void setStatus(EurekaRegistration registration, String status) {
    serviceRegistry.setStatus(registration, status);
}
 
Example #16
Source File: EurekaServiceRegistryWrapper.java    From summerframework with Apache License 2.0 4 votes vote down vote up
@Override
public Object getStatus(EurekaRegistration registration) {
    return serviceRegistry.getStatus(registration);
}
 
Example #17
Source File: ScheduleReportServerLoad.java    From summerframework with Apache License 2.0 4 votes vote down vote up
public ScheduleReportServerLoad(EurekaRegistration registration) {
    this.registration = registration;
}
 
Example #18
Source File: EurekaServiceRegistryWrapper.java    From summerframework with Apache License 2.0 4 votes vote down vote up
@Override
public void deregister(EurekaRegistration registration) {
    serviceRegistry.deregister(registration);
}
 
Example #19
Source File: EurekaServiceRegistryWrapper.java    From summerframework with Apache License 2.0 4 votes vote down vote up
public EurekaServiceRegistryWrapper(ServiceRegistry<EurekaRegistration> serviceRegistry,
    ConfigurableEnvironment environment) {
    this.serviceRegistry = serviceRegistry;
    this.environment = environment;
}
 
Example #20
Source File: MossEurekaAutoServiceRegistration.java    From Moss with 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 #21
Source File: RestTemplateGrayHeaderCustomizer.java    From summerframework with Apache License 2.0 4 votes vote down vote up
public RestTemplateGrayHeaderCustomizer(EurekaRegistration registration, GrayRulesStore grayRulesStore) {
    super(registration, grayRulesStore);
}
 
Example #22
Source File: OpenFeignGrayHeaderCustomizer.java    From summerframework with Apache License 2.0 4 votes vote down vote up
public OpenFeignGrayHeaderCustomizer(EurekaRegistration registration, GrayRulesStore grayRulesStore) {
    super(registration, grayRulesStore);
}
 
Example #23
Source File: AbstractGrayHeaderCustomizer.java    From summerframework with Apache License 2.0 4 votes vote down vote up
public AbstractGrayHeaderCustomizer(EurekaRegistration registration, GrayRulesStore grayRulesStore) {
    this.registration = registration;
    this.grayRulesStore = grayRulesStore;
}
 
Example #24
Source File: GrayAutoConfiguration.java    From summerframework with Apache License 2.0 4 votes vote down vote up
@Bean
public RestTemplateGrayHeaderCustomizer restTemplateGrayHeaderCustomizer(EurekaRegistration registration) {
    return new RestTemplateGrayHeaderCustomizer(registration, grayRulesStore);
}
 
Example #25
Source File: GrayAutoConfiguration.java    From summerframework with Apache License 2.0 4 votes vote down vote up
@Bean
public OpenFeignGrayHeaderCustomizer openFeignGrayHeaderCustomizer(EurekaRegistration registration) {
    return new OpenFeignGrayHeaderCustomizer(registration, grayRulesStore);
}
 
Example #26
Source File: GrayAutoConfiguration.java    From summerframework with Apache License 2.0 4 votes vote down vote up
@Bean
public HttpClientGrayHeaderCustomizer httpClientGrayHeaderCustomizer(EurekaRegistration registration) {
    return new HttpClientGrayHeaderCustomizer(registration, grayRulesStore);
}
 
Example #27
Source File: HttpClientGrayHeaderCustomizer.java    From summerframework with Apache License 2.0 4 votes vote down vote up
public HttpClientGrayHeaderCustomizer(EurekaRegistration registration, GrayRulesStore grayRulesStore) {
    super(registration, grayRulesStore);
}
 
Example #28
Source File: MultRegisterCenterServerMgmtConfig.java    From Moss with 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 #29
Source File: MossServerDiscoveryAutoConfiguration.java    From Moss with 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 #30
Source File: MossEurekaAutoServiceRegistration.java    From Moss with Apache License 2.0 4 votes vote down vote up
public void setRegistration(EurekaRegistration registration) {
    this.registration = registration;
}