|
@ -1,6 +1,5 @@
|
|
|
package com.yihu.hos.services;
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.hos.core.log.Logger;
|
|
|
import com.yihu.hos.core.log.LoggerFactory;
|
|
@ -9,11 +8,11 @@ import com.yihu.hos.web.framework.model.bo.ServiceMycat;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jms.core.JmsMessagingTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.zbus.broker.ZbusBroker;
|
|
|
import org.zbus.mq.Producer;
|
|
|
import org.zbus.net.http.Message;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.jms.Queue;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
/**
|
|
|
* mycat配置文件操作 消息到MQ
|
|
@ -27,12 +26,16 @@ public class ServiceMycatEventService {
|
|
|
@Autowired
|
|
|
private JmsMessagingTemplate jmsMessagingTemplate;
|
|
|
|
|
|
@Resource(name = "mycatQueue")
|
|
|
private Queue mycatQueue;
|
|
|
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
|
private ZbusBroker zbusBroker;
|
|
|
|
|
|
@Autowired
|
|
|
public void setZbusBroker(ZbusBroker zbusBroker) {
|
|
|
this.zbusBroker = zbusBroker;
|
|
|
}
|
|
|
|
|
|
public void executeMycatConfig(ServiceMycat servviceMycat, String tenant) {
|
|
|
this.sendMsg(ServiceFlowConstant.EXECUTE_MYCAT, servviceMycat,tenant);
|
|
|
}
|
|
@ -40,12 +43,17 @@ public class ServiceMycatEventService {
|
|
|
|
|
|
private void sendMsg(String event, ServiceMycat servviceMycat,String tenant) {
|
|
|
try {
|
|
|
Map<String, Object> header = new HashMap<>();
|
|
|
String msg = objectMapper.writeValueAsString(servviceMycat);
|
|
|
header.put("tenant", tenant);
|
|
|
header.put("event", event);
|
|
|
this.jmsMessagingTemplate.convertAndSend(this.mycatQueue, msg, header);
|
|
|
} catch (JsonProcessingException e) {
|
|
|
|
|
|
Producer producer = new Producer(zbusBroker, ServiceFlowConstant.MYCAT_UPDATE + "@" + tenant);
|
|
|
producer.createMQ(); //确定为创建消息队列需要显示调用
|
|
|
Message message = new Message();
|
|
|
message.setHead("event", event);
|
|
|
message.setHead("tenant", tenant);
|
|
|
message.setMethod("POST");
|
|
|
message.setBody(msg);
|
|
|
producer.sendSync(message);
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
e.printStackTrace();
|
|
|
logger.error(e.getMessage());
|
|
|
}
|