Skip to content

Instantly share code, notes, and snippets.

@songyunlu
Last active August 29, 2015 14:13
Show Gist options
  • Save songyunlu/804d83816e109bf7a17b to your computer and use it in GitHub Desktop.
Save songyunlu/804d83816e109bf7a17b to your computer and use it in GitHub Desktop.
Spring Cloud Config CassandraEnvironmentRepository
public class CassandraEnvironmentRepository implements EnvironmentRepository {
private static final Logger logger = Logger.getLogger(CassandraEnvironmentRepository.class);
@Autowired
private PropertiesRepository propertiesRepository;
@Override
public Environment findOne(final String application, final String profile, final String label) {
Environment result = new Environment(profile, label);
try {
final ConfigRepo configRepo = this.propertiesRepository.findById(application,profile,label);
if (configRepo != null) {
final Properties properties = this.loadProperties(Bytes.fromHexString(configRepo.getData()).array());
if (properties != null) {
result.add(new PropertySource(profile, properties));
}
}
} catch (final Exception e) {
CassandraEnvironmentRepository.logger.warn("Fail to fetch data from cassandra", e);
}
return result;
}
private Properties loadProperties(byte [] data) throws IOException {
Properties properties = new Properties();
properties.load(new StringReader(new String(data)));
return properties;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment