com.xt-i: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-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-heroku-registry-discovery

How to add to project

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

Dependencies

compile (6)

Group / Artifact Type Version
org.springframework.cloud : spring-cloud-commons jar 1.2.0.RELEASE
org.springframework : spring-web jar 4.3.8.RELEASE
com.thoughtworks.xstream : xstream jar 1.4.9
org.slf4j : slf4j-api jar 1.7.25
org.springframework.cloud : spring-cloud-netflix-core Optional jar
org.springframework.cloud : spring-cloud-starter-ribbon Optional jar

provided (1)

Group / Artifact Type Version
javax.servlet : javax.servlet-api jar 3.0.1

test (6)

Group / Artifact Type Version
com.github.stefanbirkner : system-rules jar 1.16.0
org.assertj : assertj-core jar 3.6.2
junit : junit jar 4.12
org.mockito : mockito-core jar 2.7.22
org.springframework.boot : spring-boot-starter-web jar 1.5.2.RELEASE
org.springframework.boot : spring-boot-starter-test jar

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