Spring Cloud 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-heroku-registry-parent
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

pom
Description

Description

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

Project URL

https://github.com/XT-i/spring-cloud-heroku-registry
Source Code Management

Source Code Management

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

Download spring-cloud-heroku-registry-parent

How to add to project

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

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • spring-cloud-heroku-registry-discovery
  • spring-cloud-starter-heroku-registry-discovery

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