Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoban3.0
haoban-manage3.0
Commits
ed8ea2c1
Commit
ed8ea2c1
authored
Oct 26, 2023
by
王祖波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stream test
parent
cc679c41
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
0 deletions
+26
-0
ContentAIController.java
...an/manage/web/controller/content/ContentAIController.java
+26
-0
No files found.
haoban-manage3-wx/src/main/java/com/gic/haoban/manage/web/controller/content/ContentAIController.java
View file @
ed8ea2c1
...
@@ -23,13 +23,16 @@ import com.gic.thirdparty.cloudfile.pojo.cme.CmeTaskProcess;
...
@@ -23,13 +23,16 @@ import com.gic.thirdparty.cloudfile.pojo.cme.CmeTaskProcess;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.mvc.method.annotation.SseEmitter
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Random
;
/**
/**
* 好办-AI创作
* 好办-AI创作
...
@@ -152,4 +155,27 @@ public class ContentAIController {
...
@@ -152,4 +155,27 @@ public class ContentAIController {
return
RestResponse
.
successResult
(
cmeTaskProcess
);
return
RestResponse
.
successResult
(
cmeTaskProcess
);
}
}
@RequestMapping
(
value
=
"/test"
,
produces
=
"text/event-stream;charset=UTF-8"
)
public
SseEmitter
streamStockPrice
()
{
SseEmitter
emitter
=
new
SseEmitter
();
// 模拟生成实时股票价格并推送给客户端
Random
random
=
new
Random
();
new
Thread
(()
->
{
try
{
while
(
true
)
{
// 生成随机的股票价格
double
price
=
100
+
random
.
nextDouble
()
*
10
;
// 构造股票价格的消息
String
message
=
String
.
format
(
"%.2f"
,
price
);
// 发送消息给客户端
emitter
.
send
(
SseEmitter
.
event
().
data
(
message
));
// 休眠1秒钟
Thread
.
sleep
(
1000
);
}
}
catch
(
Exception
e
)
{
emitter
.
completeWithError
(
e
);
}
}).
start
();
return
emitter
;
}
}
}
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