我正在努力为我的 spring aws 云 SNS http 端点找到相当于以下 xml 配置的 spring boot java 配置。有人可以帮忙吗?
<mvc:annotation-driven>
<mvc:argument-resolvers>
<ref bean="notificationResolver" />
</mvc:argument-resolvers>
</mvc:annotation-driven>
<aws-messaging:notification-argument-resolver id="notificationResolver" />
Run Code Online (Sandbox Code Playgroud) 我有一个 AWS Elastic Load Balancer,其中包含我的域的证书并终止SSL流量。该ELB有一个监听https端口,并转发为http给Zuul。
当我使用时Spring Boot HATEOAS,Zuul 将用正确的地址替换链接,http而不是https:
"_links": {
"self": {
"href": "http://my.domain.com:80/rest/foo/bar"
}
}
Run Code Online (Sandbox Code Playgroud)
但我想要的是:
"_links": {
"self": {
"href": "https://my.domain.com/rest/foo/bar"
}
}
Run Code Online (Sandbox Code Playgroud)
生成此响应的请求已完成 https
因为Zuul在 ELB 后面,我猜它不知道它应该通过 https 接收流量。
有没有办法告诉Zuul替换链接,https即使它通过 接收未加密的流量http?
我想另一种方法是使用自签名证书进行部署Zuul,https但如果可以的话,我宁愿避免这种复杂情况。
spring amazon-web-services spring-hateoas spring-cloud netflix-zuul
我有一个使用 3 个假客户端的服务。每次启动应用程序时,我都会在第一次调用任何 feign 客户端时收到 TimeoutException。
在一切稳定之前,我必须至少触发每个假客户端一次。在网上环顾四周,问题在于 feign 或 hystrix 内部的某些内容是延迟加载的,解决方案是创建一个覆盖 spring 默认值的配置类。我已经用下面的代码试过了,但它仍然没有帮助。我仍然看到同样的问题。任何人都知道解决这个问题?是通过 hystrix 回调两次调用 feignclient 的唯一解决方案吗?
@FeignClient(value = "SERVICE-NAME", configuration =ServiceFeignConfiguration.class)
@Configuration
public class ServiceFeignConfiguration {
@Value("${service.feign.connectTimeout:60000}")
private int connectTimeout;
@Value("${service.feign.readTimeOut:60000}")
private int readTimeout;
@Bean
public Request.Options options() {
return new Request.Options(connectTimeout, readTimeout);
}
}
Run Code Online (Sandbox Code Playgroud)
Spring Cloud - Brixton.SR4 Spring Boot - 1.4.0.RELEASE
这一切都在 docker Ubuntu - 12.04 Docker - 1.12.1 Docker-Compose - 1.8 中运行
我有以下设置,其中我的 Eureka 服务器正在运行,并且在 Eureka 中创建和注册的服务很少正在运行。所有服务呼叫的服务都在使用已负载平衡的休息模板进行,并且一切正常。
现在,我已经使用以下代码/属性将基于 Zuul 的路由引入到应用程序中 -
@SpringBootApplication
@EnableZuulProxy
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource= new UrlBasedCorsConfigurationSource();
final CorsConfiguration corsConfig = new CorsConfiguration();
corsConfig.setAllowCredentials(true);
corsConfig.addAllowedOrigin("*");
corsConfig.addAllowedHeader("*");
corsConfig.addAllowedMethod("OPTIONS");
corsConfig.addAllowedMethod("HEAD");
corsConfig.addAllowedMethod("GET");
corsConfig.addAllowedMethod("PUT");
corsConfig.addAllowedMethod("POST");
corsConfig.addAllowedMethod("DELETE");
corsConfig.addAllowedMethod("PATCH");
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfig);
return new CorsFilter(urlBasedCorsConfigurationSource);
}
}
Run Code Online (Sandbox Code Playgroud)
有了这个,我的路由工作得非常好,但是现在有一个服务需要接近 12 秒的执行时间,而且我的业务要求禁止打入较小的调用。
这会导致 Zuul 中的超时异常。
下面是我的 .yml 文件 -
ribbon:
ConnectTimeout: 60000
ReadTimeout: 600000
zuul:
host:
socket-timeout-millis: 60000
hystrix:
command:
default:
execution: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Spring Cloud 将一批项目发送到 Amazon SQS。我可以发送单个项目。但是,将它发送到队列的时间往往会乘以我发送的项目数。我基本上遵循参考文档的示例
在AWS 文档中,您可以一次发送最多 10 个项目的批次。所以我的问题是 QueueMessagingTemplate 或其他 Spring Cloud 类是否允许您这样做?
此代码片段显示了我想要做什么。我不想将项目作为对象发送,因为我希望每个项目都单独放置在队列中。
@Service
@EnableConfigurationProperties(SqsConfigMappingProperties.class)
public class SqsServiceImpl implements SqsService {
@Autowired
String queueName;
@Autowired
QueueMessagingTemplate queueMessagingTemplate;
@Override
public void sendSqsMessage(List items) {
//Can't really send a batch size here
int batchSize = 10;
queueMessagingTemplate.convertAndSend(queueName, items, 10);
}
}
Run Code Online (Sandbox Code Playgroud) 与spring-cloud-config集中配置类似,我们是否有集中 i18n 的东西messages.properties?这样做的最佳方法是什么?
我有一个 Spring Boot 应用程序,我要更新到 1.5.1。效果很好,直到我将 Sleuth 和 Zipkin 添加到类路径
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
当这些行出现时,我得到
2017-02-22 22:33:05.331 ERROR [chathub-api,,,] 7581 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.NoClassDefFoundError: org/springframework/boot/context/embedded/FilterRegistrationBean
Run Code Online (Sandbox Code Playgroud)
这是我的部门。管理
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)
我试着改成达尔斯顿
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
Run Code Online (Sandbox Code Playgroud)
但错误变得更加奇怪
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method …Run Code Online (Sandbox Code Playgroud) 我有两个 Spring Boot 应用程序:
cloud-config
它具有以下文件结构:
????src
????main
????environment
????default
????application.yml
????bootstrap.yml
...
Run Code Online (Sandbox Code Playgroud)
application.yml:
server:
port: 8087
spring:
cloud:
config:
server:
git:
uri: ssh://path-to-repository.git
Run Code Online (Sandbox Code Playgroud)
bootstrap.yml:
spring:
application:
name: cloud-config
Run Code Online (Sandbox Code Playgroud)main-application:
????src
????main
????environment
????default
????bootstrap.yml
????logback.xml
Run Code Online (Sandbox Code Playgroud)
我有application.yml我main-application的 git 存储库。
同样在 git 存储库中,我有一个带有属性的文件:application-default.properties.
我想转移logback.xml到 git 存储库以使用 spring-cloud 获取它。我怎样才能做到这一点?
我有简单的微服务架构:
当用户尝试登录时,凭据正在从边缘服务传递到身份验证服务。身份验证服务从用户服务(使用@FeignClient)获取用户数据,如果用户名/密码匹配,则生成令牌。没什么好看的。
这种方法有一个“小”问题:/api/user/{username}用户服务中的端点,由身份验证服务用来获取用户的数据,可能被任何用户用来获取任何其他用户的数据(密码、角色等)。一种解决方案是以某种方式为具有角色的身份验证服务创建 JWT 令牌,AUTH_SERVICE并在用户服务端检查 JWT,如果角色与AUTH_SERVICE拒绝请求不同。
还有其他解决方案吗?
编辑
我认为我的设计很常见,但显然我应该首先更具体:
编辑2:
我最终将 auth-service 合并到了 user-service,这是几个 SO 用户的建议。在考虑之后,似乎没有必要为 JWT 生成单独的身份验证服务。我已经接受了@Abhijit Sarkar 的回答,因为它有一些有效的观点,尽管他对额外调用 auth-service 以验证令牌的有效性并不正确。
我已经使用 Spring Cloud Netflix 堆栈(Eureka、Zuul、Zipkin、配置服务器等)开发了几个微服务。是否有任何开源/免费解决方案可用于启动/关闭微服务实例。例如,如果连续 3 次检查 CPU 使用率 > 90%,它将再添加一个实例。
spring-cloud ×10
spring ×6
hystrix ×2
java ×2
netflix-zuul ×2
spring-boot ×2
amazon-sqs ×1
logback ×1
oauth-2.0 ×1
spring-mvc ×1
zipkin ×1