Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
my_flask_web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit fd42a258
authored
Mar 01, 2024
by
周杭
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
线程池+MySQL连接池
1 parent
4b1edc61
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletions
kafka_consumer/ocr_consumer.py
kafka_consumer/test03.py
manage.py
kafka_consumer/ocr_consumer.py
View file @
fd42a25
This diff is collapsed.
Click to expand it.
kafka_consumer/test03.py
0 → 100644
View file @
fd42a25
import
json
from
kafka
import
KafkaProducer
# 创建Kafka生产者
producer
=
KafkaProducer
(
bootstrap_servers
=
"192.168.3.131:9092"
)
# Kafka集群的地址
# 发送消息
topic
=
"ocr_topic"
# Kafka主题名称
key
=
b
"my-key"
# 消息的键(可选)
data
=
{
'orderId'
:
321
,
'fileId'
:
31
,
'filePath'
:
'https://bhg.didihu.com.cn/group1/M00/22/05/wKgFDWWnocCAZllpAADp9tDJibY696.jpg'
,
'sns'
:
'96312110851'
,
'vin'
:
'VIN654321'
}
message
=
json
.
dumps
(
data
)
.
encode
(
'utf-8'
)
producer
.
send
(
topic
,
message
)
# 等待所有消息发送完成
producer
.
flush
()
# 关闭生产者
producer
.
close
()
manage.py
View file @
fd42a25
# coding=utf-8
# coding=utf-8
from
flask
import
request
,
render_template
from
flask
import
request
,
render_template
import
threading
from
logger
import
log
from
flaskr
import
create_app
from
flaskr
import
create_app
from
flaskr.biz
import
user_service
from
flaskr.biz
import
user_service
from
flaskr.biz.identify_service
import
IdentifyService
from
flaskr.biz.identify_service
import
IdentifyService
...
@@ -64,7 +66,11 @@ def upload():
...
@@ -64,7 +66,11 @@ def upload():
print
(
"plate_number==="
,
plate_number
)
print
(
"plate_number==="
,
plate_number
)
return
plate_number
if
plate_number
is
not
None
else
"None"
return
plate_number
if
plate_number
is
not
None
else
"None"
def
main
():
kafka_thread
=
threading
.
Thread
(
target
=
ocr_consumer
.
consume_kafka
)
kafka_thread
.
daemon
=
True
# 将线程设置为守护线程,当主线程结束时,该线程也会自动结束
kafka_thread
.
start
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
ocr_consumer
.
consume_kafka
()
main
()
app
.
run
(
host
=
"0.0.0.0"
,
port
=
5000
)
app
.
run
(
host
=
"0.0.0.0"
,
port
=
5000
)
Write
Preview
Markdown
is supported
Attach a file
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 post a comment