我正在使用Spring Boot(1.0.0.RELASE),我想创建一个包含以下内容的分发zip文件:
我希望在运行"gradle build"时创建这个zip文件(但如果很难实现,则另一项任务很好).有没有很好的方法来实现这一目标?
我正在使用Kotlin和Arrow以及. 我想做的是将Mono实例转换为Either。spring-webflux
当响应成功或返回错误时Either调用创建实例。Either.right(..)WebClientEither.left(..)WebClient
我正在寻找一种Mono类似于Either.fold(..)的方法,我可以在其中映射成功和错误的结果,并返回与Mono. 像这样的东西(伪代码不起作用):
val either : Either<Throwable, ClientResponse> =
webClient().post().exchange()
.fold({ throwable -> Either.left(throwable) },
{ response -> Either.right(response)})
Run Code Online (Sandbox Code Playgroud)
一个人应该怎样走呢?
首先,我只是想指出我已经知道Force有一个null为非可空类型和Kotlin Generics和可空类类型,但我不认为这些问题与我的相同(如果我',请更正我我错了).
背景
我正在开发一个名为Awaitility的库,简单地说,它被设计为等到谓词评估为真.该科特林API提供了一种方法来编写这样的表达式:
// Create a simple data class example
data class Data(var value: String)
// A fake repository that returns a possibly nullable instance of Data
interface DataRepository {
// Invoked from other thread
fun loadData() : Data?
}
val dataRepository = .. // Implementation of DataRepository
// Now Awaitility allows you to wait until the "value" in Data is equal to "Something"
val data : Data = await untilCallTo …Run Code Online (Sandbox Code Playgroud) 这个问题与Spring Web Flux 中的立即返回有关,但我认为不一样(至少那里的答案对我来说并不令人满意)。
我有一个函数返回一个Mono,当被调用时会启动一个长时间运行的工作。当调用 Spring Webflux HTTP API 时会调用此函数。下面是一个例子:
@PutMapping("/{jobId}")
fun startNewJob(@PathVariable("jobId") jobId: String,
request: ServerHttpRequest): Mono<ResponseEntity<Unit>> {
val longRunningJob : Mono<Job> = startNewJob(jobId)
longRunningJob.map { job ->
val jobUri = generateJobUri(request, job.id)
ResponseEntity.created(jobURI).build<Unit>()
}
}
Run Code Online (Sandbox Code Playgroud)
上面代码的问题是“201 Created”是在长时间运行的作业完成后创建的。我想longRunningJob在后台启动并立即返回“201 Created”。
我也许可以做这样的事情:
@PutMapping("/{jobId}")
fun startNewJob(@PathVariable("jobId") jobId: String,
request: ServerHttpRequest): Mono<ResponseEntity<Unit>> {
startNewJob(jobId)
.subscribeOn(Schedulers.newSingle("thread"))
.subscribe()
val jobUri = generateJobUri(request, job.id)
val response = ResponseEntity.created(jobURI).build<Unit>()
Mono.just(response)
}
Run Code Online (Sandbox Code Playgroud)
但对我来说,必须subscribe()手动调用似乎不太习惯(例如,intellij 抱怨我subscribe()在非阻塞范围内调用)。没有更好的方法来组合两个“流”而不使用显式subscribe?如果是这样,我如何修改 …
我对 dotnet 和 vscode 完全陌生,所以我可能会错过一些微不足道的东西。我只想让 F# 在我的 Mac 上的 VSCode 中运行。我首先尝试从brew安装dotnet:
brew cask install dotnet-sdk
Run Code Online (Sandbox Code Playgroud)
这似乎从命令行工作得很好,因为我可以同时执行dotnet new和dotnet build:
dotnet new console -lang F# -o myproj
Run Code Online (Sandbox Code Playgroud)
现在我安装了同样来自brew的Visual Studio Code:
brew cask install visual-studio-code
Run Code Online (Sandbox Code Playgroud)
然后我安装了Ionide-fsharp插件,myproj从 vscode 打开该文件夹并重新启动它。然后我受到的欢迎是:
FSharp.dotnetRoot然后我在设置中搜索并尝试配置它:
但这没有帮助(我也尝试将文件夹设置为/usr/local/share/dotnet但/usr/local/share/dotnet/sdk/3.1.100没有任何效果)。
所以我完全卸载了brew中的所有内容(包括擦除我的~/.vscode文件夹),并重新安装了微软官方文档中的所有内容。在文档中,它说 F# 支持应该内置到 macosx 上的 vscode 中,但当我再次打开该文件夹时,它仍然建议我安装 Ionide-fsharp,所以我服从了。但我又遇到了完全相同的问题。
所以我的问题是:如何在 MacOSX 上安装支持 F# 的 vscode?
这是我的 vscode“about”的输出:
Version: 1.41.0
Commit: 9579eda04fdb3a9bba2750f15193e5fafe16b959
Date: 2019-12-11T17:58:38.338Z
Electron: 6.1.5
Chrome: 76.0.3809.146 …Run Code Online (Sandbox Code Playgroud) 我有一对夫妇的Vavr 无论是的,我想调用函数与Right每个这些要么价值。例如:
Either<MyError, String> either1 = ..
Either<MyError, String> either2 = ..
Either<MyError, String> either3 = ..
Either<MyError, String>> methodRequiringAllInputs(String, String, String) {
..
}
Run Code Online (Sandbox Code Playgroud)
我当然可以做这样的事情:
either1.flatMap { value1 ->
either2.flatMap { value2 ->
either3.flatMap { value3 ->
methodRequiringAllInputs(value1, value2, value3);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这是非常丑陋的。在其他语言中,您可以仅使用诸如 do-notation 或推导之类的东西来使结构变平。我知道 Vavr 有一个Validation的概念,它是一个应用函子,允许您执行以下操作:
Validation<MyError, String> validation1 = ..
Validation<MyError, String> validation2 = ..
Validation<MyError, String> validation3 = ..
Validation.combine(validation1, validation2, validation3)
.ap((validationValue1,validationValue2,validationValue3) -> .. );
Run Code Online (Sandbox Code Playgroud)
这是更好的。
我的问题是,Vavr 中是否存在类似的东西,可以避免嵌套 …
我正在尝试使用Spring Security OpenId启动并运行Spring 4.0启动应用程序.我正在使用标准方式来引导Spring启动应用程序:
@Configuration
@ComponentScan("x.y.z")
@EnableAutoConfiguration
@Import({SecurityConfig.class})
public class ServiceRegistryStart extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ServiceRegistryStart.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
application.sources(getClass());
return application;
}
}
Run Code Online (Sandbox Code Playgroud)
SecurityConfig.class看起来像这样(受Spring安全性中的"openid-jc示例项目"影响):
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/resources/**").permitAll()
.anyRequest().authenticated()
.and()
.openidLogin()
.loginPage("/login.html")
.permitAll()
.authenticationUserDetailsService(new CustomUserDetailsService())
.attributeExchange("https://www.google.com/.*")
.attribute("email")
.type("http://axschema.org/contact/email")
.required(true)
.and()
.attribute("firstname")
.type("http://axschema.org/namePerson/first")
.required(true)
.and()
.attribute("lastname")
.type("http://axschema.org/namePerson/last")
.required(true)
.and()
.and()
.attributeExchange(".*yahoo.com.*")
.attribute("email")
.type("http://axschema.org/contact/email")
.required(true)
.and() …Run Code Online (Sandbox Code Playgroud) 我从服务 (S) 接收消息,该服务将每个单独的属性更改作为单独的消息发布到实体。一个人为的例子是这样的实体:
Person {
id: 123
name: "Something",
address: {...}
}
Run Code Online (Sandbox Code Playgroud)
如果名称和地址在同一事务中更新,则 (S) 将发布两条消息,PersonNameCorrected并且PersonMoved。问题出在接收端,我在那里存储该Person实体的投影,每个属性更改都会导致写入数据库。因此,在此示例中,将对数据库进行两次写入,但是如果我可以在短时间内批量处理消息并按 id 对它们进行分组,那么我只需要对数据库进行一次写入。
人们通常如何在 RabbitMQ 中处理这个问题?Spring AMQP 是否提供了更简单的抽象?
请注意,我已经简要地查看了预取,但我不确定这是否可行。另外,如果我理解正确的话,预取是基于每个连接的。我试图在每个队列的基础上实现这一点,因为如果批处理(并因此增加延迟)是要走的路,我不希望将此延迟添加到我的服务消耗的所有队列(但仅限于那些需要“group-by-id”功能)。
我们的Java DTO中通常包含一个由Javadoc中定义的表组成的更改日志:
/**
* Changelog:
*
* <table>
* <tr><th>Version</th><th>Description</th></tr>
* <tr>
* <td>2</td>
* <td>Added field 'something'</td>
* </tr>
* <tr>
* <td>3</td>
* <td>Added field 'somethingElse'</td>
* </tr>
* </table>
*/
public class MyDTO {
...
}
Run Code Online (Sandbox Code Playgroud)
这使得(在Intellij中使用Javadoc预览版)很好地呈现如下:
现在我们想为我们的Kotlin数据类做同样的事情.阅读KDoc的文档,其中说:
对于内联标记,KDoc使用常规Markdown语法,扩展为支持用于链接到代码中其他元素的简写语法.
所以我尝试使用Markdown语法创建一个表:
/**
* Changelog:
*
*| Version | Description |
*| ------------- | -------------------------- |
*| 2 | Added field 'something' |
*| 3 | Added field 'somethingElse' |
*
*/
data class MyKotlinDTO(..) {
... …Run Code Online (Sandbox Code Playgroud) 我正在使用 Java 和 Maven 来构建我的服务器应用程序(请参阅github),通常您将源代码放在文件夹中src/main/<language>并在src/test/<language>.
使用 Elm,我使用elm-explorations/test来运行我的测试(因为我使用的是 Elm 0.19),但我似乎找不到将测试文件夹更改src/test/elm为tests.
例如,我尝试过更改elm.json和添加:
"test-directories": [
"src/test/elm"
]
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用。所以我的问题是:
如何更改elm-test假设测试所在的文件夹?