Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EventTracking
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
杨林
EventTracking
Commits
523cdfcb
Commit
523cdfcb
authored
Jul 23, 2021
by
杨林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kafka类
parent
b4f5dd56
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
src/main/scala/tools/kafka/KafkaConsumer.scala
src/main/scala/tools/kafka/KafkaConsumer.scala
+39
-0
No files found.
src/main/scala/tools/kafka/KafkaConsumer.scala
0 → 100644
View file @
523cdfcb
package
tools.kafka
import
java.util.Properties
import
org.apache.flink.api.common.serialization.SimpleStringSchema
import
org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer
import
org.apache.kafka.clients.consumer.ConsumerConfig
import
tools.properties.PropertiesTools
/**
* Created with IntelliJ IDEA.
* Class: KafkaConsumer
* Description: 创建kafka消费者
* User: lin
* Date: 2021-07-19
* Time: 16:19
*/
object
KafkaConsumer
{
private
[
this
]
val
properties
:
Properties
=
PropertiesTools
.
getProperties
private
[
this
]
val
bootstrapServer
:
String
=
properties
.
getProperty
(
"kafka.cluster"
)
private
[
this
]
val
keyDeserializer
:
String
=
properties
.
getProperty
(
"kafka.consumer.key.deserializer"
)
private
[
this
]
val
valueDeserializer
:
String
=
properties
.
getProperty
(
"kafka.consumer.value.deserializer"
)
private
[
this
]
val
commitInterval
:
String
=
properties
.
getProperty
(
"kafka.consumer.offset.commit.auto.interval"
)
private
[
this
]
val
AutoCommit
:
String
=
properties
.
getProperty
(
"kafka.consumer.offset.commit.auto"
)
private
[
this
]
val
group
:
String
=
properties
.
getProperty
(
"kafka.consumer.group"
)
private
[
this
]
val
topic
:
String
=
properties
.
getProperty
(
"kafka.event.topic"
)
def
getConsumer
:
FlinkKafkaConsumer
[
String
]
=
{
val
property
=
new
Properties
()
// 对接kafka
property
.
put
(
ConsumerConfig
.
BOOTSTRAP_SERVERS_CONFIG
,
bootstrapServer
)
property
.
put
(
ConsumerConfig
.
GROUP_ID_CONFIG
,
group
)
property
.
put
(
ConsumerConfig
.
KEY_DESERIALIZER_CLASS_CONFIG
,
keyDeserializer
)
property
.
put
(
ConsumerConfig
.
VALUE_DESERIALIZER_CLASS_CONFIG
,
valueDeserializer
)
property
.
put
(
ConsumerConfig
.
AUTO_COMMIT_INTERVAL_MS_CONFIG
,
commitInterval
)
property
.
put
(
ConsumerConfig
.
ENABLE_AUTO_COMMIT_CONFIG
,
AutoCommit
)
new
FlinkKafkaConsumer
[
String
](
topic
,
new
SimpleStringSchema
(),
property
)
}
}
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