Remove netflix dependencies
There's no need to depend on netflix libraries but the sample was using Ribbon, so we took that out so that the release can be independent.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.cloudfoundry.sample;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.cloudfoundry.discovery.CloudFoundryDiscoveryClient;
|
||||
import org.springframework.cloud.cloudfoundry.discovery.EnableCloudFoundryClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* This example assumes you've registered an application on
|
||||
* <A href="http://cloudfoundry.org">Cloud Foundry</A> named {@code hi-service} that
|
||||
* responds with a String at {@code /hi/ name} . There is a sample file in the project
|
||||
* root called {@code hi-service.groovy} which you can deploy using the {@code spring} CLI
|
||||
* and the {@code cf} CLI that works appropriately for this demonstration.
|
||||
*
|
||||
* @author <a href="mailto:josh@joshlong.com">Josh Long</a>
|
||||
* @author Spencer Gibb
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableCloudFoundryClient
|
||||
public class CloudFoundryApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CloudFoundryApplication.class, args);
|
||||
}
|
||||
|
||||
private Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Bean
|
||||
CommandLineRunner consume(final CloudFoundryDiscoveryClient discoveryClient) {
|
||||
|
||||
return new CommandLineRunner() {
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
|
||||
// this demonstrates using the Spring Cloud Commons DiscoveryClient
|
||||
// abstraction
|
||||
log.info("=====================================");
|
||||
for (String svc : discoveryClient.getServices()) {
|
||||
log.info("service = " + svc);
|
||||
List<ServiceInstance> instances = discoveryClient.getInstances(svc);
|
||||
for (ServiceInstance si : instances) {
|
||||
log.info("\t" + si);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("=====================================");
|
||||
log.info("local: ");
|
||||
log.info("\t" + discoveryClient.getLocalServiceInstance());
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.cloudfoundry.sample;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
|
||||
import org.springframework.cloud.cloudfoundry.discovery.CloudFoundryDiscoveryClient;
|
||||
import org.springframework.cloud.cloudfoundry.discovery.EnableCloudFoundryClient;
|
||||
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* This example assumes you've registered an application on <A
|
||||
* href="http://cloudfoundry.org">Cloud Foundry</A> named {@code hi-service} that responds
|
||||
* with a String at {@code /hi/ name} . There is a sample file in the project root called
|
||||
* {@code hi-service.groovy} which you can deploy using the {@code spring} CLI and the
|
||||
* {@code cf} CLI that works appropriately for this demonstration.
|
||||
*
|
||||
* @author <a href="mailto:josh@joshlong.com">Josh Long</a>
|
||||
* @author Spencer Gibb
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableCloudFoundryClient
|
||||
@EnableFeignClients
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
private Log log = LogFactory.getLog(getClass());
|
||||
|
||||
@Bean
|
||||
CommandLineRunner consume(final LoadBalancerClient loadBalancerClient,
|
||||
final CloudFoundryDiscoveryClient discoveryClient, final HiServiceClient hiServiceClient,
|
||||
final RestTemplate restTemplate) {
|
||||
|
||||
return new CommandLineRunner() {
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
|
||||
try {
|
||||
// this demonstrates using the CF/Ribbon-aware RestTemplate
|
||||
// interceptor
|
||||
log.info("=====================================");
|
||||
log.info("Hi: "
|
||||
+ restTemplate.getForEntity("http://hi-service/hi/{name}",
|
||||
String.class, "Josh"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("Failed to fetch hi-service", e);
|
||||
}
|
||||
|
||||
// this demonstrates using the Spring Cloud Commons DiscoveryClient
|
||||
// abstraction
|
||||
log.info("=====================================");
|
||||
for (String svc : discoveryClient.getServices()) {
|
||||
log.info("service = " + svc);
|
||||
List<ServiceInstance> instances = discoveryClient.getInstances(svc);
|
||||
for (ServiceInstance si : instances) {
|
||||
log.info("\t"
|
||||
+ ReflectionToStringBuilder.reflectionToString(si,
|
||||
ToStringStyle.MULTI_LINE_STYLE));
|
||||
}
|
||||
}
|
||||
|
||||
log.info("=====================================");
|
||||
log.info("local: ");
|
||||
log.info("\t"
|
||||
+ ReflectionToStringBuilder.reflectionToString(
|
||||
discoveryClient.getLocalServiceInstance(),
|
||||
ToStringStyle.MULTI_LINE_STYLE));
|
||||
|
||||
try {
|
||||
// this demonstrates using a CF/Ribbon-aware Feign client
|
||||
log.info("=====================================");
|
||||
log.info("Hi:" + hiServiceClient.hi("Josh"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.warn("Failed to fetch hi-service", e);
|
||||
}
|
||||
|
||||
// this demonstrates using the Spring Cloud Commons LoadBalancerClient
|
||||
log.info("=====================================");
|
||||
ServiceInstance choose = loadBalancerClient.choose("hi-service");
|
||||
if (choose != null) {
|
||||
log.info("chose: " + '(' + choose.getServiceId() + ") "
|
||||
+ choose.getHost() + ':' + choose.getPort());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@FeignClient("hi-service")
|
||||
interface HiServiceClient {
|
||||
|
||||
@RequestMapping(value = "/hi/{name}", method = RequestMethod.GET)
|
||||
Map<String, Object> hi(@PathVariable("name") String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cloud.cloudfoundry.sample;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = CloudFoundryApplication.class)
|
||||
@IntegrationTest
|
||||
@WebAppConfiguration
|
||||
@Ignore("Need to configure spring.cloud.cloudfoundry.discovery.email/password")
|
||||
public class CloudFoundryApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user