mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-12 04:16:51 +08:00
feat: 停止当前聊天输出接口功能完善
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.xboe.config;
|
package com.xboe.config;
|
||||||
|
|
||||||
import org.apache.activemq.command.ActiveMQTopic;
|
import org.apache.activemq.command.ActiveMQTopic;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.jms.annotation.EnableJms;
|
import org.springframework.jms.annotation.EnableJms;
|
||||||
@@ -14,12 +15,16 @@ import javax.jms.Topic;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class MqConfig {
|
public class MqConfig {
|
||||||
|
|
||||||
|
@Value("${activemq.topic.name}")
|
||||||
|
private String topicName;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置topic
|
* 配置topic
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public Topic broadcastTopic() {
|
public Topic broadcastTopic() {
|
||||||
return new ActiveMQTopic("broadcast.session.termination");
|
return new ActiveMQTopic(topicName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 配置JmsListenerContainerFactory为发布/订阅模式
|
// 配置JmsListenerContainerFactory为发布/订阅模式
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ public class BroadcastMessageConsumer {
|
|||||||
*
|
*
|
||||||
* @param conversationId 会话ID
|
* @param conversationId 会话ID
|
||||||
*/
|
*/
|
||||||
@JmsListener(destination = "broadcast.session.termination",
|
@JmsListener(destination = "${activemq.topic.name}")
|
||||||
containerFactory = "jmsListenerContainerFactory")
|
|
||||||
public void receiveSessionTerminationBroadcastMessage(String conversationId) {
|
public void receiveSessionTerminationBroadcastMessage(String conversationId) {
|
||||||
log.info("收到会话终止广播消息:{}", conversationId);
|
log.info("收到会话终止广播消息:{}", conversationId);
|
||||||
iCaseAiChatService.eventSourceCancel(conversationId);
|
iCaseAiChatService.eventSourceCancel(conversationId);
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import javax.jms.Topic;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -106,8 +107,8 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private JmsTemplate jmsTemplate;
|
private JmsTemplate jmsTemplate;
|
||||||
|
|
||||||
@Value("${activemq.topic.name}")
|
@Autowired
|
||||||
private String topicName;
|
private Topic topic;
|
||||||
|
|
||||||
// 用于存储会话ID与EventSource的映射关系,以便能够中断特定会话
|
// 用于存储会话ID与EventSource的映射关系,以便能够中断特定会话
|
||||||
private final Map<String, EventSource> conversationEventSourceMap = new ConcurrentHashMap<>();
|
private final Map<String, EventSource> conversationEventSourceMap = new ConcurrentHashMap<>();
|
||||||
@@ -772,7 +773,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
log.info("收到停止会话 {} 的指令", conversationId);
|
log.info("收到停止会话 {} 的指令", conversationId);
|
||||||
// 发送广播消息,通知中断连接
|
// 发送广播消息,通知中断连接
|
||||||
try {
|
try {
|
||||||
jmsTemplate.convertAndSend(topicName, conversationId);
|
jmsTemplate.convertAndSend(topic, conversationId);
|
||||||
} catch (JmsException e) {
|
} catch (JmsException e) {
|
||||||
log.error("发送停止会话 {} 输出时发生异常", conversationId, e);
|
log.error("发送停止会话 {} 输出时发生异常", conversationId, e);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -35,6 +35,12 @@ spring:
|
|||||||
connection-timeout: 30000
|
connection-timeout: 30000
|
||||||
max-lifetime: 1800000
|
max-lifetime: 1800000
|
||||||
maximum-pool-size: 20
|
maximum-pool-size: 20
|
||||||
|
activemq:
|
||||||
|
broker-url: tcp://192.168.0.253:61616
|
||||||
|
user: admin
|
||||||
|
password: admin
|
||||||
|
jms:
|
||||||
|
pub-sub-domain: true
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
org:
|
org:
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ spring:
|
|||||||
web:
|
web:
|
||||||
resources:
|
resources:
|
||||||
static-locations: file:E:/Projects/BOE/10/static
|
static-locations: file:E:/Projects/BOE/10/static
|
||||||
|
activemq:
|
||||||
|
broker-url: tcp://10.251.129.51:61616
|
||||||
|
user: admin
|
||||||
|
password: admin
|
||||||
|
jms:
|
||||||
|
pub-sub-domain: true
|
||||||
server:
|
server:
|
||||||
port: 9090
|
port: 9090
|
||||||
tomcat:
|
tomcat:
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ spring:
|
|||||||
connection-timeout: 30000
|
connection-timeout: 30000
|
||||||
max-lifetime: 1800000
|
max-lifetime: 1800000
|
||||||
maximum-pool-size: 20
|
maximum-pool-size: 20
|
||||||
|
activemq:
|
||||||
|
broker-url: tcp://10.251.113.100:61616
|
||||||
|
user: admin
|
||||||
|
password: admin
|
||||||
|
jms:
|
||||||
|
pub-sub-domain: true
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
org:
|
org:
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ spring:
|
|||||||
web:
|
web:
|
||||||
resources:
|
resources:
|
||||||
static-locations: file:E:/Projects/BOE/10/static
|
static-locations: file:E:/Projects/BOE/10/static
|
||||||
|
activemq:
|
||||||
|
broker-url: tcp://10.251.129.25:61616
|
||||||
|
user: admin
|
||||||
|
password: admin
|
||||||
|
jms:
|
||||||
|
pub-sub-domain: true
|
||||||
server:
|
server:
|
||||||
port: 9090
|
port: 9090
|
||||||
tomcat:
|
tomcat:
|
||||||
|
|||||||
Reference in New Issue
Block a user