Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
schbrain-parent
Commits
07c629ca
Commit
07c629ca
authored
Dec 22, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve kafka integration
parent
9b1c8308
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
8 deletions
+19
-8
starters/kafka-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/kafka/CustomKafkaListenerEndpointRegistry.java
...oconfigure/kafka/CustomKafkaListenerEndpointRegistry.java
+7
-6
starters/starrocks-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/starrocks/helper/ConvertUtils.java
...ramework/autoconfigure/starrocks/helper/ConvertUtils.java
+10
-2
support/schbrain-spring-support/src/main/java/com/schbrain/framework/support/spring/env/DefaultPropertiesEnvironmentPostProcessor.java
...spring/env/DefaultPropertiesEnvironmentPostProcessor.java
+2
-0
No files found.
starters/kafka-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/kafka/CustomKafkaListenerEndpointRegistry.java
View file @
07c629ca
...
@@ -14,19 +14,20 @@ public class CustomKafkaListenerEndpointRegistry extends KafkaListenerEndpointRe
...
@@ -14,19 +14,20 @@ public class CustomKafkaListenerEndpointRegistry extends KafkaListenerEndpointRe
private
static
final
String
CONSUMER_ENABLED_KEY
=
"spring.kafka.consumer.enabled"
;
private
static
final
String
CONSUMER_ENABLED_KEY
=
"spring.kafka.consumer.enabled"
;
private
final
KafkaProperties
kafkaProperties
;
private
final
boolean
shouldRegisterConsumer
;
public
CustomKafkaListenerEndpointRegistry
(
KafkaProperties
kafkaProperties
)
{
public
CustomKafkaListenerEndpointRegistry
(
KafkaProperties
kafkaProperties
)
{
this
.
kafkaProperties
=
kafkaProperties
;
this
.
shouldRegisterConsumer
=
EnvUtils
.
runningOnCloudPlatform
()
||
kafkaProperties
.
getConsumer
().
isEnabled
();
if
(!
shouldRegisterConsumer
)
{
log
.
warn
(
"Not running on CloudPlatform or {} is set to false, will not listen to messages from brokers"
,
CONSUMER_ENABLED_KEY
);
log
.
warn
(
"If you want force to register with Kafka Brokers, set {} = true"
,
CONSUMER_ENABLED_KEY
);
}
}
}
@Override
@Override
public
void
registerListenerContainer
(
KafkaListenerEndpoint
endpoint
,
KafkaListenerContainerFactory
<?>
factory
,
boolean
startImmediately
)
{
public
void
registerListenerContainer
(
KafkaListenerEndpoint
endpoint
,
KafkaListenerContainerFactory
<?>
factory
,
boolean
startImmediately
)
{
if
(
EnvUtils
.
runningOnCloudPlatform
()
||
kafkaProperties
.
getConsumer
().
isEnabled
()
)
{
if
(
shouldRegisterConsumer
)
{
super
.
registerListenerContainer
(
endpoint
,
factory
,
startImmediately
);
super
.
registerListenerContainer
(
endpoint
,
factory
,
startImmediately
);
}
else
{
log
.
warn
(
"Not running on CloudPlatform or {} is set to false, will not listen to messages from brokers"
,
CONSUMER_ENABLED_KEY
);
log
.
warn
(
"If you want force to register with Kafka Brokers, set {} = true"
,
CONSUMER_ENABLED_KEY
);
}
}
}
}
...
...
starters/starrocks-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/starrocks/helper/ConvertUtils.java
View file @
07c629ca
...
@@ -18,12 +18,20 @@ public class ConvertUtils {
...
@@ -18,12 +18,20 @@ public class ConvertUtils {
private
static
final
ObjectMapper
DESERIALIZER
=
JacksonUtils
.
getObjectMapper
().
copy
().
setPropertyNamingStrategy
(
PropertyNamingStrategies
.
SNAKE_CASE
);
private
static
final
ObjectMapper
DESERIALIZER
=
JacksonUtils
.
getObjectMapper
().
copy
().
setPropertyNamingStrategy
(
PropertyNamingStrategies
.
SNAKE_CASE
);
public
static
<
Source
,
Target
>
Target
convertTo
(
ConsumerRecord
<
String
,
String
>
record
,
Class
<
Source
>
sourceType
,
Class
<
Target
>
targetType
)
{
public
static
<
Target
>
Target
convertTo
(
ConsumerRecord
<
String
,
String
>
record
,
Class
<
Target
>
targetType
)
{
CanalChangedEvent
event
=
JacksonUtils
.
getObjectFromJson
(
record
.
value
(),
CanalChangedEvent
.
class
);
CanalChangedEvent
event
=
JacksonUtils
.
getObjectFromJson
(
record
.
value
(),
CanalChangedEvent
.
class
);
if
(
event
==
null
)
{
if
(
event
==
null
)
{
throw
new
BaseException
(
"CanalChangedEvent is null"
);
throw
new
BaseException
(
"CanalChangedEvent is null"
);
}
}
Source
source
=
DESERIALIZER
.
convertValue
(
event
.
getAfter
(),
sourceType
);
return
DESERIALIZER
.
convertValue
(
event
.
getAfter
(),
targetType
);
}
public
static
<
Target
>
List
<
Target
>
convertToList
(
ConsumerRecords
<
String
,
String
>
records
,
Class
<
Target
>
targetType
)
{
return
StreamUtils
.
toList
(
records
,
record
->
convertTo
(
record
,
targetType
));
}
public
static
<
Source
,
Target
>
Target
convertTo
(
ConsumerRecord
<
String
,
String
>
record
,
Class
<
Source
>
sourceType
,
Class
<
Target
>
targetType
)
{
Source
source
=
convertTo
(
record
,
sourceType
);
return
BeanCopyUtils
.
copy
(
source
,
targetType
);
return
BeanCopyUtils
.
copy
(
source
,
targetType
);
}
}
...
...
support/schbrain-spring-support/src/main/java/com/schbrain/framework/support/spring/env/DefaultPropertiesEnvironmentPostProcessor.java
View file @
07c629ca
...
@@ -61,6 +61,8 @@ public class DefaultPropertiesEnvironmentPostProcessor extends LoggerAwareEnviro
...
@@ -61,6 +61,8 @@ public class DefaultPropertiesEnvironmentPostProcessor extends LoggerAwareEnviro
defaultProperties
.
put
(
"spring.mvc.format.date-time"
,
DatePattern
.
NORM_DATETIME_PATTERN
);
defaultProperties
.
put
(
"spring.mvc.format.date-time"
,
DatePattern
.
NORM_DATETIME_PATTERN
);
defaultProperties
.
put
(
"spring.jackson.date-format"
,
DatePattern
.
NORM_DATETIME_PATTERN
);
defaultProperties
.
put
(
"spring.jackson.date-format"
,
DatePattern
.
NORM_DATETIME_PATTERN
);
defaultProperties
.
put
(
"spring.jackson.time-zone"
,
TimeZone
.
getDefault
().
getID
());
defaultProperties
.
put
(
"spring.jackson.time-zone"
,
TimeZone
.
getDefault
().
getID
());
// kafka
defaultProperties
.
put
(
"spring.kafka.consumer.group-id"
,
ApplicationName
.
get
(
environment
));
// others
// others
defaultProperties
.
put
(
"spring.mandatory-file-encoding"
,
StandardCharsets
.
UTF_8
.
name
());
defaultProperties
.
put
(
"spring.mandatory-file-encoding"
,
StandardCharsets
.
UTF_8
.
name
());
defaultProperties
.
put
(
"spring.web.resources.add-mappings"
,
false
);
defaultProperties
.
put
(
"spring.web.resources.add-mappings"
,
false
);
...
...
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