Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
0843bf24
Commit
0843bf24
authored
Apr 07, 2022
by
王亮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unit test env,for adding NAMESPACE scope logic.
parent
6380b45e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
1 deletion
+10
-1
KafkaMeterRegistry.java
...oup/ext/micrometer/register/kafka/KafkaMeterRegistry.java
+10
-1
No files found.
qg-micrometer-register-kafka-starter/src/main/java/cn/quantgroup/ext/micrometer/register/kafka/KafkaMeterRegistry.java
View file @
0843bf24
...
@@ -23,6 +23,7 @@ import java.util.stream.Stream;
...
@@ -23,6 +23,7 @@ import java.util.stream.Stream;
import
org.apache.kafka.clients.producer.KafkaProducer
;
import
org.apache.kafka.clients.producer.KafkaProducer
;
import
org.apache.kafka.clients.producer.ProducerConfig
;
import
org.apache.kafka.clients.producer.ProducerConfig
;
import
org.apache.kafka.clients.producer.ProducerRecord
;
import
org.apache.kafka.clients.producer.ProducerRecord
;
import
org.springframework.util.ObjectUtils
;
public
class
KafkaMeterRegistry
extends
StepMeterRegistry
{
public
class
KafkaMeterRegistry
extends
StepMeterRegistry
{
...
@@ -31,10 +32,18 @@ public class KafkaMeterRegistry extends StepMeterRegistry {
...
@@ -31,10 +32,18 @@ public class KafkaMeterRegistry extends StepMeterRegistry {
private
final
KafkaConfig
config
;
private
final
KafkaConfig
config
;
private
KafkaProducer
<
String
,
String
>
kafkaProducer
;
private
KafkaProducer
<
String
,
String
>
kafkaProducer
;
private
final
String
key
;
public
KafkaMeterRegistry
(
KafkaConfig
config
,
Clock
clock
)
{
public
KafkaMeterRegistry
(
KafkaConfig
config
,
Clock
clock
)
{
super
(
config
,
clock
);
super
(
config
,
clock
);
this
.
config
=
config
;
this
.
config
=
config
;
if
(
ObjectUtils
.
isEmpty
(
System
.
getProperty
(
"NAMESPACE"
)))
{
key
=
"default"
;
}
else
{
key
=
System
.
getProperty
(
"NAMESPACE"
);
}
Properties
properties
=
new
Properties
();
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
ProducerConfig
.
BOOTSTRAP_SERVERS_CONFIG
,
config
.
services
());
properties
.
setProperty
(
ProducerConfig
.
BOOTSTRAP_SERVERS_CONFIG
,
config
.
services
());
properties
.
setProperty
(
ProducerConfig
.
KEY_SERIALIZER_CLASS_CONFIG
,
properties
.
setProperty
(
ProducerConfig
.
KEY_SERIALIZER_CLASS_CONFIG
,
...
@@ -66,7 +75,7 @@ public class KafkaMeterRegistry extends StepMeterRegistry {
...
@@ -66,7 +75,7 @@ public class KafkaMeterRegistry extends StepMeterRegistry {
counter
->
writeCounter
(
counter
.
getId
(),
counter
.
count
()),
counter
->
writeCounter
(
counter
.
getId
(),
counter
.
count
()),
this
::
writeFunctionTimer
,
this
::
writeFunctionTimer
,
this
::
writeMeter
)).
forEach
(
i
->
{
this
::
writeMeter
)).
forEach
(
i
->
{
kafkaProducer
.
send
(
new
ProducerRecord
<>(
config
.
topic
(),
i
));
kafkaProducer
.
send
(
new
ProducerRecord
<>(
config
.
topic
(),
key
,
i
));
});
});
}
}
}
}
...
...
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