这两种方法有什么区别:Optional.flatMap()和Optional.map()?
一个例子将不胜感激.
我是开发微服务的新手,虽然我已经研究了一段时间,阅读了Spring的文档和Netflix.
我已经在Github上开始了一个简单的项目.它基本上是Eureka服务器(阿基米德)和三个Eureka客户端微服务(一个公共API和两个私有).查看github的自述文件以获取详细说明.
关键是当一切都在运行时,我希望如果其中一个私有微服务被杀死,Eureka服务器会实现并从注册表中删除它.
我在Stackoverflow上发现了这个问题,解决方案通过enableSelfPreservation:false在Eureka Server配置中使用.一段时间后执行此操作,被杀死的服务会按预期消失.
但是我可以看到以下消息:
自保护模式已关闭.在网络/其他问题的情况下,可能无法保护实例.
1.自我保护的目的是什么?该文件指出,对"客户端进行自我保护可以获得不再存在的实例".那么什么时候打开/关闭它是否明智?
此外,启用自我保护后,您可能会在Eureka Server控制台警告中收到一条未完成的消息:
紧急!当EUREKA不是时,EUREKA可能会不正当地提出申请.更新的数量超过了阈值,并且这些实际情况并未到期,只是为了安全起见.
现在,继续使用Spring Eureka控制台.
Lease expiration enabled true/false
Renews threshold 5
Renews (last min) 4
Run Code Online (Sandbox Code Playgroud)
我遇到了一个奇怪的阈值计数行为:当我单独启动Eureka Server时,阈值为1.
2.我有一个Eureka服务器并配置registerWithEureka: false为防止它在另一台服务器上注册.那么,为什么它会显示在阈值计数中?
3.对于每个客户端,我开始阈值计数增加+2.我想这是因为他们每分钟发送2条续订消息,对不对?
4. Eureka服务器永远不会发送续订,因此最后一次更新时间始终低于阈值.这是正常的吗?
renew threshold 5
rewnews last min: (client1) +2 + (client2) +2 -> 4
Run Code Online (Sandbox Code Playgroud)
服务器cfg:
server:
port: ${PORT:8761}
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
enableSelfPreservation: false
# waitTimeInMsWhenSyncEmpty: 0 …Run Code Online (Sandbox Code Playgroud) 我试图通过AWS API Gateway调用Lambda函数.当我提到身份验证类型为NONE时它工作正常但API变为公共,任何有url的人都可以访问我的API.为了使API调用安全,我使用身份验证类型AWS_IAM并将AmazonAPIGatewayInvokeFullAccess策略附加到我的用户但收到此错误:
{message:"缺少身份验证令牌"}
我不知道我在这里失踪了什么.
我在Windows上运行Docker(boot2docker + Oracle Virtual Box).在我的公司环境中,他们修改证书,以便CA是公司的自签名CA. 因此,链条最终会像这样:
Company's CA
|__
Company's Intermediate CA
|__
Docker Certificate
Run Code Online (Sandbox Code Playgroud)
当我尝试运行任何命令时,例如:
docker run hello-world
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Get https://index.docker.io/v1/repositories/library/hello-world/images: x509: certificate signed by unknown authority
Run Code Online (Sandbox Code Playgroud)
我已经找到了这个问题的几个答案,但总是针对Linux环境.如何在Windows中解决此问题?
Spring 5为webflux引入了rest API的反应式编程风格.我自己也很陌生,并且想知道将数据库的同步调用包装成有意义Flux还是Mono有意义?如果是,这是这样做的方式:
@RestController
public class HomeController {
private MeasurementRepository repository;
public HomeController(MeasurementRepository repository){
this.repository = repository;
}
@GetMapping(value = "/v1/measurements")
public Flux<Measurement> getMeasurements() {
return Flux.fromIterable(repository.findByFromDateGreaterThanEqual(new Date(1486980000L)));
}
}
Run Code Online (Sandbox Code Playgroud)
是否有类似异步CrudRepository的东西?我找不到它.
是否有一种简单的方法可以为所有Actuator端点添加前缀?
/env -> /secure/env
/health -> /secure/health
/info -> /secure/info
...
Run Code Online (Sandbox Code Playgroud) Sinks.Many<String>在使用向多个订阅者通知某些事件时,我遇到了一种我不明白的行为:
fun main() {
val sink : Sinks.Many<String> = Sinks.many().multicast().onBackpressureBuffer()
val flux = sink.asFlux().log()
val d = flux.subscribe {
println("--> $it")
}
sink.emitNext("1", Sinks.EmitFailureHandler.FAIL_FAST)
val d2 = flux.subscribe {
println("--2> $it")
}
sink.emitNext("2", Sinks.EmitFailureHandler.FAIL_FAST)
}
Run Code Online (Sandbox Code Playgroud)
此代码显示第一个订阅者获取值 1 和 2,第二个订阅者获取值 2。到目前为止一切顺利:
11:49:06.936 [main] INFO reactor.Flux.EmitterProcessor.1 - onSubscribe(EmitterProcessor.EmitterInner)
11:49:06.938 [main] INFO reactor.Flux.EmitterProcessor.1 - request(unbounded)
11:49:06.942 [main] INFO reactor.Flux.EmitterProcessor.1 - onNext(1)
--> 1
11:49:06.942 [main] INFO reactor.Flux.EmitterProcessor.1 - onSubscribe(EmitterProcessor.EmitterInner)
11:49:06.942 [main] INFO reactor.Flux.EmitterProcessor.1 - request(unbounded)
11:49:06.943 [main] INFO reactor.Flux.EmitterProcessor.1 - onNext(2)
--> …Run Code Online (Sandbox Code Playgroud) 我已将Spring Boot应用程序配置为将日期序列化为ISO8601字符串:
spring:
jackson:
serialization:
write-dates-as-timestamps: false
Run Code Online (Sandbox Code Playgroud)
这就是我得到的:
"someDate": "2017-09-11T07:53:27.000+0000"
Run Code Online (Sandbox Code Playgroud)
不过我的时区是欧洲/马德里.事实上,如果我打印TimeZone.getDefault()这是我得到的.
如何让杰克逊使用实际时区序列化这些日期时间值?GMT + 2
"someDate": "2017-09-11T09:53:27.000+0200"
Run Code Online (Sandbox Code Playgroud) 我有控制器这么简单:
@RequestMapping(value="/async/data", method=RequestMethod.GET, produces="application/json")
@ApiOperation(value = "Gets data", notes="Gets data asynchronously")
@ApiResponses(value={@ApiResponse(code=200, message="OK")})
public Callable<List<Data>> getData(){
return ( () -> {return dataService.loadData();} );
}
Run Code Online (Sandbox Code Playgroud)
我期望只有HTTP状态200的响应消息.但是springfox总是生成下面的那些(401,403,404).如何禁用(不显示)它们?
async-rest-controller Show/Hide List Operations Expand Operations
GET /async/data Gets data
Implementation Notes
Gets data asynchronously
Response Class (Status 200)
ModelModel Schema
{}
Response Content Type
Response Messages
HTTP Status Code Reason Response Model Headers
401 Unauthorized
403 Forbidden
404 Not Found
Run Code Online (Sandbox Code Playgroud) 我能够从IntelliJ 2017.3推出Spring Boot Kotlin应用程序.在最后一次IntelliJ修复更新后,我无法从IDE启动该应用程序,获得此异常:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: @Configuration class 'AccessConfig' may not be final
Run Code Online (Sandbox Code Playgroud)
我可以像往常一样从终端开始: java -jar xxxx.jar
这没有任何意义,因为我在Gradle配置中使用了必要的Kotlin Spring插件:
buildscript {
ext {
kotlinVersion = '1.2.21'
springBootVersion = '2.0.0.RC1'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3'
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.5"
}
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply …Run Code Online (Sandbox Code Playgroud) spring ×5
spring-boot ×3
kotlin ×2
spring-mvc ×2
boot2docker ×1
docker ×1
gradle ×1
jackson ×1
jackson2 ×1
java ×1
java-8 ×1
optional ×1
spring-cloud ×1
swagger ×1
swagger-ui ×1
virtualbox ×1
windows ×1