Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
tb_goods
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
bigdata
tb_goods
Commits
13a045da
Commit
13a045da
authored
Jun 11, 2021
by
杨林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kafka消费者
parent
7522a1a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
0 deletions
+37
-0
src/main/scala/tools/kafka/KafkaConsumer.scala
src/main/scala/tools/kafka/KafkaConsumer.scala
+37
-0
No files found.
src/main/scala/tools/kafka/KafkaConsumer.scala
0 → 100644
View file @
13a045da
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
/**
* @ClassName: KafkaConsumer
* @Description: TODO
* @Create by: LinYoung
* @Date: 2021/1/13 14:54
*/
object
KafkaConsumer
{
private
[
this
]
val
properties
:
Properties
=
PropertiesTools
.
getProperties
private
[
this
]
val
topic
:
String
=
properties
.
getProperty
(
"kafka.topic"
)
private
[
this
]
val
bootstrapServer
:
String
=
properties
.
getProperty
(
"kafka.cluster"
)
private
[
this
]
val
group
:
String
=
properties
.
getProperty
(
"kafka.consumer.group"
)
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"
)
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