org.springframework.cloud.client.discovery.ManagementServerPortUtils Java Examples

The following examples show how to use org.springframework.cloud.client.discovery.ManagementServerPortUtils. 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: NacosRegistration.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() {

	Map<String, String> metadata = nacosDiscoveryProperties.getMetadata();
	Environment env = context.getEnvironment();

	String endpointBasePath = env.getProperty(MANAGEMENT_ENDPOINT_BASE_PATH);
	if (!StringUtils.isEmpty(endpointBasePath)) {
		metadata.put(MANAGEMENT_ENDPOINT_BASE_PATH, endpointBasePath);
	}

	Integer managementPort = ManagementServerPortUtils.getPort(context);
	if (null != managementPort) {
		metadata.put(MANAGEMENT_PORT, managementPort.toString());
		String contextPath = env
				.getProperty("management.server.servlet.context-path");
		String address = env.getProperty("management.server.address");
		if (!StringUtils.isEmpty(contextPath)) {
			metadata.put(MANAGEMENT_CONTEXT_PATH, contextPath);
		}
		if (!StringUtils.isEmpty(address)) {
			metadata.put(MANAGEMENT_ADDRESS, address);
		}
	}

	if (null != nacosDiscoveryProperties.getHeartBeatInterval()) {
		metadata.put(PreservedMetadataKeys.HEART_BEAT_INTERVAL,
				nacosDiscoveryProperties.getHeartBeatInterval().toString());
	}
	if (null != nacosDiscoveryProperties.getHeartBeatTimeout()) {
		metadata.put(PreservedMetadataKeys.HEART_BEAT_TIMEOUT,
				nacosDiscoveryProperties.getHeartBeatTimeout().toString());
	}
	if (null != nacosDiscoveryProperties.getIpDeleteTimeout()) {
		metadata.put(PreservedMetadataKeys.IP_DELETE_TIMEOUT,
				nacosDiscoveryProperties.getIpDeleteTimeout().toString());
	}
}
 
Example #2
Source File: AbstractAutoServiceRegistration.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether the management service should be registered with the
 * {@link ServiceRegistry}.
 */
protected boolean shouldRegisterManagement() {
	if (this.properties == null || this.properties.isRegisterManagement()) {
		return getManagementPort() != null
				&& ManagementServerPortUtils.isDifferent(this.context);
	}
	return false;
}
 
Example #3
Source File: ConsulAutoRegistration.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
/**
 * @param autoServiceRegistrationProperties registration properties
 * @param properties discovery properties
 * @param context Spring application context
 * @return if the management service should be registered with the
 * {@link ServiceRegistry}
 */
public static boolean shouldRegisterManagement(
		AutoServiceRegistrationProperties autoServiceRegistrationProperties,
		ConsulDiscoveryProperties properties, ApplicationContext context) {
	return autoServiceRegistrationProperties.isRegisterManagement()
			&& getManagementPort(properties, context) != null
			&& ManagementServerPortUtils.isDifferent(context);
}
 
Example #4
Source File: ConsulAutoRegistration.java    From spring-cloud-consul with Apache License 2.0 5 votes vote down vote up
/**
 * @param properties discovery properties
 * @param context Spring application context
 * @return the port of the Management Service
 */
public static Integer getManagementPort(ConsulDiscoveryProperties properties,
		ApplicationContext context) {
	// If an alternate external port is specified, use it instead
	if (properties.getManagementPort() != null) {
		return properties.getManagementPort();
	}
	return ManagementServerPortUtils.getPort(context);
}
 
Example #5
Source File: AbstractAutoServiceRegistration.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
/**
 * @return The management server port.
 */
@Deprecated
protected Integer getManagementPort() {
	return ManagementServerPortUtils.getPort(this.context);
}