私たちは、spring-boot-starter-redis
とspring-boot-starter-data-redis
と一緒にspring-boot-starter-parent
1.4.1を使用しています。私たちは、(a)外部アプリにメッセージを渡し、(b)リポジトリに情報を保存するためにredisを使用します。これにより、この春データRedis - リポジトリのトランザクションサポート@
@Configuration
@EnableRedisRepositories
open class RedisConfig {
@Bean // for message passing
@Profile("test")
open fun testRedisChannelProvider(): RedisParserChannelProvider {
return RedisParserChannelProvider("test_parser:parse.job", "test_parser:parse.joblist")
}
@Bean // for message passing
@Profile("!test")
open fun productionRedisChannelProvider(): RedisParserChannelProvider {
return RedisParserChannelProvider("parser:parse.job", "parser:parse.joblist")
}
@Bean // for message passing
open fun parseJobTemplate(connectionFactory: RedisConnectionFactory): RedisTemplate<String, ParseJob> {
val template = RedisTemplate<String, ParseJob>()
template.connectionFactory = connectionFactory
template.valueSerializer = Jackson2JsonRedisSerializer<ParseJob>(ParseJob::class.java)
return template
}
//@Bean // for message passing
//open fun parseJobListTemplate ...
// no template for repository
は、メッセージパッシングがうまく働くだけでなく、リポジトリからの読み取り/書き込みにされconfigコンのように私たちのRedisのconfigが見えます。今私は@Transactional
リポジトリとの通信のために働こうとしているが、私はこれまで成功していない。私はすでにそれにdocsの例の設定と手動で有効にトランザクションのサポートに続く:
@Bean
open fun redisTemplate(): RedisTemplate<*, *> {
val template = RedisTemplate<ByteArray, ByteArray>()
template.setEnableTransactionSupport(true)
return template
}
を...しかし、これは明らかに移動するための方法ではありません。現在、リポジトリに書き込まれたものはすべて(特にテスト中に)そこにとどまります。