为了熟悉Spring Cloud的Eureka客户端/服务器机制,我尝试将客户端连接到Eureka服务器并每隔5分钟打开/关闭连接,以查看Eureka服务器如何处理此问题.
我有两个Eureka客户.
第一个是通过以下代码向我提供有关已注册应用程序的信息:
@Autowired
private DiscoveryClient discoveryClient;
@RequestMapping(value = "/services", produces = MediaType.APPLICATION_JSON)
public ResponseEntity<ResourceSupport> applications() {
ResourceSupport resource = new ResourceSupport();
Set<String> regions = discoveryClient.getAllKnownRegions();
for (String region : regions) {
Applications allApps = discoveryClient.getApplicationsForARegion(region);
List<Application> registeredApps = allApps.getRegisteredApplications();
Iterator<Application> it = registeredApps.iterator();
while (it.hasNext()) {
Application app = it.next();
List<InstanceInfo> instancesInfos = app.getInstances();
if (instancesInfos != null && !instancesInfos.isEmpty()) {
//only show one of the instances
InstanceInfo info = instancesInfos.get(0);
resource.add(new Link(info.getHomePageUrl(), "urls"));
}
}
}
return …Run Code Online (Sandbox Code Playgroud) spring service-discovery spring-boot spring-cloud netflix-eureka
我所描述的安装在我的本地机器上cloudfoundry 这里,现在我想安装春季云服务也是如此.但是我不知道在哪里可以找到OpsManager,我怀疑它是否部署完毕.所以问题是 - 是否可以在不使用OpsManager的情况下安装Spring Cloud Services,如果是这样,如何实现呢?
提前致谢!
我的批处理必须使用OAuth2与grant-type Client Credential连接到Web服务
这是代码:
ClientCredentialsResourceDetails resource = new ClientCredentialsResourceDetails();
resource.setAccessTokenUri(accessTokenUri);
resource.setClientId(clientId);
resource.setClientSecret(clientSecret);
ClientCredentialsAccessTokenProvider provider = new ClientCredentialsAccessTokenProvider();
OAuth2AccessToken accessToken = provider.obtainAccessToken(resource, new DefaultAccessTokenRequest());
Run Code Online (Sandbox Code Playgroud)
当执行此代码时,它发出一个请求,其中grant_type在post值中,但clientId和客户端机密放在带有经典基本auth头的头中:
Authorization: Basic bXktY2xpZW50LWlkIDpteS1jbGllbnQtc2VjcmV0
Run Code Online (Sandbox Code Playgroud)
如果我解码字符串bXktY2xpZW50LWlkIDpteS1jbGllbnQtc2VjcmV0
decode64(bXktY2xpZW50LWlkIDpteS1jbGllbnQtc2VjcmV0) -> my-client-id:my-client-secret
Run Code Online (Sandbox Code Playgroud)
这通常很好.但是我们必须使用的Web服务不支持这一点,我们必须将client-id和client-secret放在post-value之类的grant-type中.
有没有办法实现这一目标?一种配置如何发送客户端ID和客户端密钥的方法?
迈克尔
spring spring-security spring-boot spring-security-oauth2 spring-cloud
我想在加载Spring上下文之前添加一些查找,理想情况是在Spring Cloud的引导阶段(当它查找Configuration Server,云连接器等时).如何让我的代码在该阶段执行?
我想要做的是查询Vault以获取我的所有数据库机密和api密钥并设置属性,我知道我可以使用Spring Cloud Config加密,但我喜欢强大的Vault框.(与我可以处理的Vault部分集成)
我在Rabbit代工厂运行RabbitMQ并尝试从本地运行的配置服务器连接,下面是在application.yml文件中配置的内容
spring
rabbitmq:
host: xxxx
vhost: xxxx
port: 5672
username: xxx
password: xxx
Run Code Online (Sandbox Code Playgroud)
抛出启动异常
org.springframework.context.ApplicationContextException: Failed to start bean 'outputBindingLifecycle'; nested exception is org.springframework.amqp.AmqpTimeoutException: java.util.concurrent.TimeoutException
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:852) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.boot.test.SpringApplicationContextLoader.loadContext(SpringApplicationContextLoader.java:98) [spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:228) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:230) [spring-test-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at …Run Code Online (Sandbox Code Playgroud) 假装默认扩展器转换参数?
final class ToStringExpander implements Expander {
@Override
public String expand(Object value) {
return value.toString();
}
}
Run Code Online (Sandbox Code Playgroud)
我想自定义它来转换用户以支持GET参数,像这样
@FeignClient("xx")
interface UserService{
@RequestMapping(value="/users",method=GET)
public List<User> findBy(@ModelAttribute User user);
}
userService.findBy(user);
Run Code Online (Sandbox Code Playgroud)
我能做什么?
我想使用swagger-codegen生成我的假装客户端代码,但我找不到可以引导我去做的文档.
我有一个使用spring cloud的微服务,几个api-services使用spring-cloud-feign接口来请求数据.我希望我可以生成假装客户端代码.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>http://localhost:9141/v2/api-docs?group=building-service-api</inputSpec>
<language>java</language>
<output>${project.build.directory}/generated-sources/swagger</output>
<library>feign</library>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
语言/库设置为'java/feign',只有没有假装客户端的模型;
语言设置为'spring','feign'是不受支持的库.
我很困惑如何生成我的所有代码?似乎几乎没有指南或文档或演示?
openjdk:10.0.1-jre-slim我有一个名为serviceA并关联的功能区客户端
serviceA.ribbon.ConnectTimeout=5000
serviceA.ribbon.ReadTimeout=15000
hystrix.command.serviceA.execution.isolation.thread.timeoutInMilliseconds = 20000
Run Code Online (Sandbox Code Playgroud)
我还没有(知道)在类路径上进行spring-retry。我执行./mvnw dependency:list | grep -i retry并没有结果。
在运行时,我收到以下警告:
命令serviceA的Hystrix超时20000ms设置为小于功能区读取和连接超时的组合40000ms。
考虑到我认为分别将它们设置为15秒和5秒,因此我不确定这些数字来自何处。为什么这个数字翻倍?
hystrix spring-cloud spring-cloud-feign netflix-ribbon spring-cloud-netflix
为什么我们需要Spring Cloud?AWS和Spring Cloud有什么区别?
我在github repo中查看了许多spring cloud config服务器的代码,下面是作为属性文件的一部分提供的2个值。我相信为了连接到github的https端点,用户名和密码也是必需的。这些可能是环境变量的一部分吗?
server.port=7070
spring.cloud.config.server.git.uri=https://
Run Code Online (Sandbox Code Playgroud)
编辑:
下面是我在春季网站上看到的示例。但是在我企业中的所有github仓库中,我都看不到设置的用户名和密码,因为它们是敏感信息。如果属性文件中未提供uid / pwd,如何设置或配置服务器访问github url?
spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
username: trolley
password: strongpassword
Run Code Online (Sandbox Code Playgroud)