Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
0e5f55f2
Commit
0e5f55f2
authored
Oct 11, 2016
by
Jason Song
Committed by
GitHub
Oct 11, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #424 from nobodyiam/SimpleApolloConfigDemo
add SimpleApolloConfigDemo
parents
7e55899a
042cfb81
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
SimpleApolloConfigDemo.java
apollo-demo/src/main/java/SimpleApolloConfigDemo.java
+64
-0
No files found.
apollo-demo/src/main/java/SimpleApolloConfigDemo.java
0 → 100644
View file @
0e5f55f2
import
com.google.common.base.Charsets
;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.ConfigChangeListener
;
import
com.ctrip.framework.apollo.ConfigService
;
import
com.ctrip.framework.apollo.model.ConfigChange
;
import
com.ctrip.framework.apollo.model.ConfigChangeEvent
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public
class
SimpleApolloConfigDemo
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
SimpleApolloConfigDemo
.
class
);
private
String
DEFAULT_VALUE
=
"undefined"
;
private
Config
config
;
public
SimpleApolloConfigDemo
()
{
ConfigChangeListener
changeListener
=
new
ConfigChangeListener
()
{
@Override
public
void
onChange
(
ConfigChangeEvent
changeEvent
)
{
logger
.
info
(
"Changes for namespace {}"
,
changeEvent
.
getNamespace
());
for
(
String
key
:
changeEvent
.
changedKeys
())
{
ConfigChange
change
=
changeEvent
.
getChange
(
key
);
logger
.
info
(
"Change - key: {}, oldValue: {}, newValue: {}, changeType: {}"
,
change
.
getPropertyName
(),
change
.
getOldValue
(),
change
.
getNewValue
(),
change
.
getChangeType
());
}
}
};
config
=
ConfigService
.
getAppConfig
();
config
.
addChangeListener
(
changeListener
);
}
private
String
getConfig
(
String
key
)
{
String
result
=
config
.
getProperty
(
key
,
DEFAULT_VALUE
);
logger
.
info
(
String
.
format
(
"Loading key : %s with value: %s"
,
key
,
result
));
return
result
;
}
public
static
void
main
(
String
[]
args
)
throws
IOException
{
SimpleApolloConfigDemo
apolloConfigDemo
=
new
SimpleApolloConfigDemo
();
System
.
out
.
println
(
"Apollo Config Demo. Please input key to get the value. Input quit to exit."
);
while
(
true
)
{
System
.
out
.
print
(
"> "
);
String
input
=
new
BufferedReader
(
new
InputStreamReader
(
System
.
in
,
Charsets
.
UTF_8
)).
readLine
();
if
(
input
==
null
||
input
.
length
()
==
0
)
{
continue
;
}
input
=
input
.
trim
();
if
(
input
.
equalsIgnoreCase
(
"quit"
))
{
System
.
exit
(
0
);
}
apolloConfigDemo
.
getConfig
(
input
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment