Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
211010717
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2021
211010717
Commits
20e21a1f
Unverified
Commit
20e21a1f
authored
4 years ago
by
slinpq
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feature:support configuring apolloService and apolloCluster (#3116)
parent
8dc7b224
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
config/seata-config-apollo/src/main/java/io/seata/config/apollo/ApolloConfiguration.java
+26
-7
26 additions, 7 deletions
...main/java/io/seata/config/apollo/ApolloConfiguration.java
server/src/main/resources/registry.conf
+3
-0
3 additions, 0 deletions
server/src/main/resources/registry.conf
with
29 additions
and
7 deletions
config/seata-config-apollo/src/main/java/io/seata/config/apollo/ApolloConfiguration.java
+
26
−
7
View file @
20e21a1f
...
...
@@ -55,9 +55,13 @@ public class ApolloConfiguration extends AbstractConfiguration {
private
static
final
String
APP_ID
=
"appId"
;
private
static
final
String
APOLLO_META
=
"apolloMeta"
;
private
static
final
String
APOLLO_SECRET
=
"apolloAccesskeySecret"
;
private
static
final
String
APOLLO_CLUSTER
=
"seata"
;
private
static
final
String
APOLLO_CONFIG_SERVICE
=
"apolloConfigService"
;
private
static
final
String
PROP_APP_ID
=
"app.id"
;
private
static
final
String
PROP_APOLLO_META
=
"apollo.meta"
;
private
static
final
String
PROP_APOLLO_CONFIG_SERVICE
=
"apollo.configService"
;
private
static
final
String
PROP_APOLLO_SECRET
=
"apollo.accesskey.secret"
;
private
static
final
String
PROP_APOLLO_CLUSTER
=
"apollo.cluster"
;
private
static
final
String
NAMESPACE
=
"namespace"
;
private
static
final
String
DEFAULT_NAMESPACE
=
"application"
;
private
static
final
Configuration
FILE_CONFIG
=
ConfigurationFactory
.
CURRENT_FILE_INSTANCE
;
...
...
@@ -65,7 +69,7 @@ public class ApolloConfiguration extends AbstractConfiguration {
private
ExecutorService
configOperateExecutor
;
private
static
final
int
CORE_CONFIG_OPERATE_THREAD
=
1
;
private
static
final
ConcurrentMap
<
String
,
Set
<
ConfigurationChangeListener
>>
LISTENER_SERVICE_MAP
=
new
ConcurrentHashMap
<>();
=
new
ConcurrentHashMap
<>();
private
static
final
int
MAX_CONFIG_OPERATE_THREAD
=
2
;
private
static
volatile
ApolloConfiguration
instance
;
...
...
@@ -76,9 +80,9 @@ public class ApolloConfiguration extends AbstractConfiguration {
if
(
config
==
null
)
{
config
=
ConfigService
.
getConfig
(
FILE_CONFIG
.
getConfig
(
getApolloNamespaceKey
(),
DEFAULT_NAMESPACE
));
configOperateExecutor
=
new
ThreadPoolExecutor
(
CORE_CONFIG_OPERATE_THREAD
,
MAX_CONFIG_OPERATE_THREAD
,
Integer
.
MAX_VALUE
,
TimeUnit
.
MILLISECONDS
,
new
LinkedBlockingQueue
<>(),
new
NamedThreadFactory
(
"apolloConfigOperate"
,
MAX_CONFIG_OPERATE_THREAD
));
MAX_CONFIG_OPERATE_THREAD
,
Integer
.
MAX_VALUE
,
TimeUnit
.
MILLISECONDS
,
new
LinkedBlockingQueue
<>(),
new
NamedThreadFactory
(
"apolloConfigOperate"
,
MAX_CONFIG_OPERATE_THREAD
));
config
.
addChangeListener
(
changeEvent
->
{
for
(
String
key
:
changeEvent
.
changedKeys
())
{
if
(!
LISTENER_SERVICE_MAP
.
containsKey
(
key
))
{
...
...
@@ -86,7 +90,7 @@ public class ApolloConfiguration extends AbstractConfiguration {
}
ConfigChange
change
=
changeEvent
.
getChange
(
key
);
ConfigurationChangeEvent
event
=
new
ConfigurationChangeEvent
(
key
,
change
.
getNamespace
(),
change
.
getOldValue
(),
change
.
getNewValue
(),
getChangeType
(
change
.
getChangeType
()));
change
.
getOldValue
(),
change
.
getNewValue
(),
getChangeType
(
change
.
getChangeType
()));
LISTENER_SERVICE_MAP
.
get
(
key
).
forEach
(
listener
->
listener
.
onProcessEvent
(
event
));
}
});
...
...
@@ -118,12 +122,12 @@ public class ApolloConfiguration extends AbstractConfiguration {
return
value
;
}
ConfigFuture
configFuture
=
new
ConfigFuture
(
dataId
,
defaultValue
,
ConfigFuture
.
ConfigOperation
.
GET
,
timeoutMills
);
timeoutMills
);
configOperateExecutor
.
submit
(()
->
{
String
result
=
config
.
getProperty
(
dataId
,
defaultValue
);
configFuture
.
setResult
(
result
);
});
return
(
String
)
configFuture
.
get
();
return
(
String
)
configFuture
.
get
();
}
@Override
...
...
@@ -180,6 +184,12 @@ public class ApolloConfiguration extends AbstractConfiguration {
System
.
setProperty
(
PROP_APOLLO_SECRET
,
secretKey
);
}
}
if
(!
properties
.
containsKey
(
APOLLO_CLUSTER
))
{
System
.
setProperty
(
PROP_APOLLO_CLUSTER
,
FILE_CONFIG
.
getConfig
(
getApolloCluster
()));
}
if
(!
properties
.
containsKey
(
APOLLO_CONFIG_SERVICE
))
{
System
.
setProperty
(
PROP_APOLLO_CONFIG_SERVICE
,
FILE_CONFIG
.
getConfig
(
getApolloConfigService
()));
}
}
@Override
...
...
@@ -203,6 +213,15 @@ public class ApolloConfiguration extends AbstractConfiguration {
return
String
.
join
(
FILE_CONFIG_SPLIT_CHAR
,
FILE_ROOT_CONFIG
,
REGISTRY_TYPE
,
NAMESPACE
);
}
private
static
String
getApolloCluster
()
{
return
String
.
join
(
FILE_CONFIG_SPLIT_CHAR
,
FILE_ROOT_CONFIG
,
REGISTRY_TYPE
,
APOLLO_CLUSTER
);
}
private
static
String
getApolloConfigService
()
{
return
String
.
join
(
FILE_CONFIG_SPLIT_CHAR
,
FILE_ROOT_CONFIG
,
REGISTRY_TYPE
,
APOLLO_CONFIG_SERVICE
);
}
private
ConfigurationChangeType
getChangeType
(
PropertyChangeType
changeType
)
{
switch
(
changeType
)
{
case
ADDED:
...
...
This diff is collapsed.
Click to expand it.
server/src/main/resources/registry.conf
+
3
−
0
View file @
20e21a1f
...
...
@@ -72,9 +72,12 @@ config {
}
apollo
{
appId
=
"seata-server"
## apolloConfigService will cover apolloMeta
apolloMeta
=
"http://192.168.1.204:8801"
apolloConfigService
=
"http://192.168.1.204:8080"
namespace
=
"application"
apolloAccesskeySecret
=
""
cluster
=
"seata"
}
zk
{
serverAddr
=
"127.0.0.1:2181"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment