com.xt-i:spring-cloud-starter-heroku-registry-discovery

Spring Cloud DiscoveryClient implementation running on Heroku Private Spaces DNS Registry.

License

License

Categories

Categories

Heroku Container PaaS Providers
GroupId

GroupId

com.xt-i
ArtifactId

ArtifactId

spring-cloud-starter-heroku-registry-discovery
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Spring Cloud DiscoveryClient implementation running on Heroku Private Spaces DNS Registry.

Download spring-cloud-starter-heroku-registry-discovery

How to add to project

<!-- https://jarcasting.com/artifacts/com.xt-i/spring-cloud-starter-heroku-registry-discovery/ -->
<dependency>
    <groupId>com.xt-i</groupId>
    <artifactId>spring-cloud-starter-heroku-registry-discovery</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.xt-i/spring-cloud-starter-heroku-registry-discovery/
implementation 'com.xt-i:spring-cloud-starter-heroku-registry-discovery:1.0.1'
// https://jarcasting.com/artifacts/com.xt-i/spring-cloud-starter-heroku-registry-discovery/
implementation ("com.xt-i:spring-cloud-starter-heroku-registry-discovery:1.0.1")
'com.xt-i:spring-cloud-starter-heroku-registry-discovery:jar:1.0.1'
<dependency org="com.xt-i" name="spring-cloud-starter-heroku-registry-discovery" rev="1.0.1">
  <artifact name="spring-cloud-starter-heroku-registry-discovery" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.xt-i', module='spring-cloud-starter-heroku-registry-discovery', version='1.0.1')
)
libraryDependencies += "com.xt-i" % "spring-cloud-starter-heroku-registry-discovery" % "1.0.1"
[com.xt-i/spring-cloud-starter-heroku-registry-discovery "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
com.xt-i : spring-cloud-heroku-registry-discovery jar 1.0.1

Project Modules

There are no modules declared in this project.

spring-cloud-heroku-registry Build Status Codacy Badge

Spring Cloud Discovery extension based on Heroku Private Spaces Registry.

More information about Heroku DNS registry: https://devcenter.heroku.com/articles/dyno-dns-registry

Service discovery is performed by depending on the /etc/heroku/space-topology.json file which is updated within 10 seconds of topology changes.

Usage

Depend on the following spring starter dependency:

<dependency>
    <groupId>com.xt-i</groupId>
    <artifactId>spring-cloud-starter-heroku-registry-discovery</artifactId>
    <version>1.0.1</version>
</dependency>

Use a standard Heroku Java Procfile

web: java $JAVA_WEB_OPTS -Dserver.port=$PORT -jar target/*.jar

Configuration without client loadbalancing support

Use the following Spring annotations on your configuration class to run the application on Heroku. The embedded tomcat will both run on the $PORT used by the Heroku loadbalancer and the internally used 8080 port by processes within the Private Space. This internal port can overridden by setting the SPRING_CLOUD_HEROKU_PORT environment variable. By default a filter will run causing the /spring-cloud-heroku-metadata endpoint to be only available on the internal port.

@Configuration
@EnableDiscoveryClient
public class YourConfigClass {

    @Value("${SPRING_CLOUD_HEROKU_PORT:8080}")
    private String springCloudHerokuPort;

    @Bean
    public EmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(Integer.valueOf(springCloudHerokuPort));
        tomcat.addAdditionalTomcatConnectors(connector);
        return tomcat;
    }
}

Configuration with client loadbalancing support (RestTemplate with Ribbon)

Depend on the following additional dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-ribbon</artifactId>
    <version>1.2.0.RELEASE</version>
</dependency>

Add @EnableAutoConfiguration annotation to the configuration to register beans used by Ribbon. Also register a @LoadBalanced RestTemplate bean.

@Configuration
@EnableDiscoveryClient
@EnableAutoConfiguration
public class YourConfigClass {

    @Value("${SPRING_CLOUD_HEROKU_PORT:8080}")
    private String springCloudHerokuPort;

    @Bean
    public EmbeddedServletContainerFactory servletContainer() {
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(Integer.valueOf(springCloudHerokuPort));
        tomcat.addAdditionalTomcatConnectors(connector);
        return tomcat;
    }

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}

Use the @LoadBalanced RestTemplate bean where necessary by using {processName}.{appName} as host.

@Service
public class MyService {
    
    @Autowired
    private RestTemplate restTemplate;
    
    public void call(){
        restTemplate.getForObject("http://processname.herokuapp/api/hello", String.class);
    }
}

Example

https://github.com/XT-i/spring-cloud-heroku-registry-example

com.xt-i

XTi

Versions

Version
1.0.1
1.0.0
0.2.0
0.1.1
0.1