| 1 | |
package com.ctrip.apollo.adminservice; |
| 2 | |
|
| 3 | |
import com.ctrip.apollo.biz.message.DummyMessageSender; |
| 4 | |
import com.ctrip.apollo.biz.message.MessageSender; |
| 5 | |
import com.ctrip.apollo.biz.message.RedisMessageSender; |
| 6 | |
|
| 7 | |
import org.springframework.beans.factory.annotation.Value; |
| 8 | |
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| 9 | |
import org.springframework.context.annotation.Bean; |
| 10 | |
import org.springframework.context.annotation.Configuration; |
| 11 | |
import org.springframework.data.redis.connection.RedisConnectionFactory; |
| 12 | |
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; |
| 13 | |
import org.springframework.data.redis.core.RedisTemplate; |
| 14 | |
import org.springframework.data.redis.core.StringRedisTemplate; |
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
@Configuration |
| 20 | 1 | public class AdminServiceAutoConfiguration { |
| 21 | |
@ConditionalOnProperty(value = "apollo.redis.enabled", havingValue = "true", matchIfMissing = false) |
| 22 | 0 | public static class AdminRedisConfiguration { |
| 23 | |
@Value("${apollo.redis.host}") |
| 24 | |
private String host; |
| 25 | |
@Value("${apollo.redis.port}") |
| 26 | |
private int port; |
| 27 | |
@Bean |
| 28 | |
public JedisConnectionFactory redisConnectionFactory() { |
| 29 | 0 | JedisConnectionFactory factory = new JedisConnectionFactory(); |
| 30 | 0 | factory.setHostName(host); |
| 31 | 0 | factory.setPort(port); |
| 32 | 0 | return factory; |
| 33 | |
} |
| 34 | |
|
| 35 | |
@Bean |
| 36 | |
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) { |
| 37 | 0 | StringRedisTemplate template = new StringRedisTemplate(factory); |
| 38 | 0 | return template; |
| 39 | |
} |
| 40 | |
|
| 41 | |
@Bean |
| 42 | |
public MessageSender redisMessageSender(RedisTemplate<String, String> redisTemplate) { |
| 43 | 0 | return new RedisMessageSender(redisTemplate); |
| 44 | |
} |
| 45 | |
|
| 46 | |
} |
| 47 | |
|
| 48 | 1 | @Configuration |
| 49 | |
@ConditionalOnProperty(value = "apollo.redis.enabled", havingValue = "false", matchIfMissing = true) |
| 50 | 1 | public static class ConfigDefaultConfiguration { |
| 51 | |
@Bean |
| 52 | |
public MessageSender defaultMessageSender() { |
| 53 | 1 | return new DummyMessageSender(); |
| 54 | |
} |
| 55 | |
} |
| 56 | |
} |