org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration Java Examples

The following examples show how to use org.springframework.cloud.consul.serviceregistry.ConsulAutoRegistration. 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: DubboServiceRegistrationNonWebApplicationAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 6 votes vote down vote up
/**
 * Set port on Non-Web Application.
 * @param consulRegistration {@link ConsulRegistration}
 */
private void setPort(ConsulAutoRegistration consulRegistration) {
	int port = consulRegistration.getPort();
	NewService newService = consulRegistration.getService();
	if (newService.getPort() == null) {
		newService.setPort(port);
	}
}
 
Example #2
Source File: GrpcConsulRegistrar.java    From grpc-spring-boot-starter with Apache License 2.0 6 votes vote down vote up
private ConsulRegistration getRegistration(GRpcServerInitializedEvent event) {
    ApplicationContext applicationContext = event.getApplicationContext();


    ConsulDiscoveryProperties consulProperties = applicationContext.getBean(ConsulDiscoveryProperties.class);
    GRpcServerProperties gRpcServerProperties = event.getApplicationContext().getBean(GRpcServerProperties.class);

    NewService grpcService = new NewService();
    grpcService.setPort(event.getServer().getPort());
    if (!consulProperties.isPreferAgentAddress()) {
        grpcService.setAddress(consulProperties.getHostname());
    }
    String appName = "grpc-" + ConsulAutoRegistration.getAppName(consulProperties, applicationContext.getEnvironment());
    grpcService.setName(ConsulAutoRegistration.normalizeForDns(appName));
    grpcService.setId("grpc-" + ConsulAutoRegistration.getInstanceId(consulProperties, applicationContext));
    grpcService.setTags(ConsulAutoRegistration.createTags(consulProperties)
            .stream()
            .filter(t->!t.startsWith("secure="))
            .collect(Collectors.toList())
    );


    if(consulProperties.isRegisterHealthCheck()) {
        GRpcConsulHealthCheck health = GRpcConsulHealthCheck.builder()
                .socketAddr(consulProperties.getHostname() + ":" + event.getServer().getPort())
                .grpcUseTlc(Objects.nonNull(gRpcServerProperties.getSecurity()))
                .interval(consulProperties.getHealthCheckInterval())
                .timeout(consulProperties.getHealthCheckTimeout())
                .build();

        health.setDeregisterCriticalServiceAfter(consulProperties.getHealthCheckCriticalTimeout());

        grpcService.setCheck(health);
    }



    return new ConsulRegistration(grpcService, consulProperties);
}
 
Example #3
Source File: ConsulLightminClientDiscoveryConfiguration.java    From spring-batch-lightmin with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean(ConsulAutoRegistration.class)
public ConsulAutoRegistration consulAutoRegistration(
        final MetaDataExtender metaDataExtender,
        final AutoServiceRegistrationProperties autoServiceRegistrationProperties,
        final ConsulDiscoveryProperties consulDiscoveryProperties,
        final ApplicationContext applicationContext,
        final List<ConsulRegistrationCustomizer> consulRegistrationCustomizers,
        final List<ConsulManagementRegistrationCustomizer> managementRegistrationCustomizers,
        final HeartbeatProperties heartbeatProperties) {

    metaDataExtender.extendMetaData();
    return ConsulAutoRegistration.registration(
            autoServiceRegistrationProperties,
            consulDiscoveryProperties,
            applicationContext,
            consulRegistrationCustomizers,
            managementRegistrationCustomizers,
            heartbeatProperties);
}
 
Example #4
Source File: SidecarConsulAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@Bean
public ConsulAutoRegistration consulRegistration(
		AutoServiceRegistrationProperties autoServiceRegistrationProperties,
		ConsulDiscoveryProperties properties, ApplicationContext applicationContext,
		ObjectProvider<List<ConsulRegistrationCustomizer>> registrationCustomizers,
		ObjectProvider<List<ConsulManagementRegistrationCustomizer>> managementRegistrationCustomizers,
		HeartbeatProperties heartbeatProperties,
		SidecarProperties sidecarProperties) {
	return SidecarConsulAutoRegistration.registration(
			autoServiceRegistrationProperties, properties, applicationContext,
			registrationCustomizers.getIfAvailable(),
			managementRegistrationCustomizers.getIfAvailable(), heartbeatProperties,
			sidecarProperties);
}
 
Example #5
Source File: SidecarConsulAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@Bean
public SidecarDiscoveryClient sidecarDiscoveryClient(
		ConsulDiscoveryProperties properties, ConsulServiceRegistry serviceRegistry,
		ConsulAutoRegistration registration) {
	return new SidecarConsulDiscoveryClient(properties, serviceRegistry,
			registration);
}
 
Example #6
Source File: DubboServiceRegistrationNonWebApplicationAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
/**
 * Handle the pre-registered event of {@link ServiceInstance} for Consul.
 * @param event {@link ServiceInstancePreRegisteredEvent}
 */
@EventListener(ServiceInstancePreRegisteredEvent.class)
public void onServiceInstancePreRegistered(
		ServiceInstancePreRegisteredEvent event) {
	Registration registration = event.getSource();
	ConsulAutoRegistration consulRegistration = (ConsulAutoRegistration) registration;
	setPort(consulRegistration);
}
 
Example #7
Source File: SidecarConsulDiscoveryClient.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
public SidecarConsulDiscoveryClient(ConsulDiscoveryProperties properties,
		ConsulServiceRegistry serviceRegistry, ConsulAutoRegistration registration) {
	this.properties = properties;
	this.serviceRegistry = serviceRegistry;
	this.registration = registration;
}