Prechádzať zdrojové kódy

ibmmq添加datasourceid参数方法

andy 1 rok pred
rodič
commit
58282e5e7b

+ 67 - 2
src/main/java/com/scbfkj/uni/process/IBMMQ.java

@@ -16,20 +16,45 @@ import org.springframework.jms.core.JmsTemplate;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 
 
 public class IBMMQ {
 
-
+    private static final DataBase DATA_BASE = new DataBase();
     private JmsTemplate jmsTemplate = null;
 
     private final ObjectMapper mapper = new ObjectMapper();
 
+    public List<String> receptionMessageByDataSourceId( String dataSourceId, String channel, String queueManager, String queueName, Long ccsid, Long receiveTimeout, Long pollSize, Long retry) throws Exception {
+        Map<String,Object> config = queryConnectionStr(dataSourceId);
+
+        long port = 1414L;
+        String host = Objects.toString(config.get("host"));
+        if(host.contains(":")){
+            String[] split = host.split(":");
+            port = Long.parseLong(split[1]);
+            host = split[0];
+        }
+        String username =null;
+        String password =null;
+        Object username1 = config.get("username");
+        if(Objects.nonNull(username1)){
+            username = username1.toString();
+        }
+        Object password1 = config.get("password");
+        if(Objects.nonNull(password1)){
+            password = password1.toString();
+        }
+        return receptionMessage(host,port,channel,queueManager,queueName,ccsid,username,password,receiveTimeout,pollSize,retry);
+
+    }
+
     public List<String> receptionMessage(
             String host, Long port, String channel, String queueManager, String queueName, Long ccsid, String username, String password, Long receiveTimeout, Long pollSize, Long retry) throws JMSException {
         JmsTemplate template = getJmsTemplate(host, port.intValue(), ccsid.intValue(), queueManager, channel, username, password);
 
-
         jmsTemplate.setReceiveTimeout(receiveTimeout);
         long maxSize = 100;
         if (pollSize > 0) {
@@ -71,6 +96,31 @@ public class IBMMQ {
     }
 
 
+    public void sendMessageByDataSourceId(
+            String dataSourceId, String channel, String queueManager, String queueName, Long ccsid,
+            Object data
+    ) throws Exception {
+        Map<String,Object> config = queryConnectionStr(dataSourceId);
+
+        long port = 1414L;
+        String host = Objects.toString(config.get("host"));
+        if(host.contains(":")){
+            String[] split = host.split(":");
+            port = Long.parseLong(split[1]);
+            host = split[0];
+        }
+        String username =null;
+        String password =null;
+        Object username1 = config.get("username");
+        if(Objects.nonNull(username1)){
+            username = username1.toString();
+        }
+        Object password1 = config.get("password");
+        if(Objects.nonNull(password1)){
+            password = password1.toString();
+        }
+        sendMessage(host,port,channel,queueManager,queueName,ccsid,username,password,data);
+    }
     public void sendMessage(
             String host, Long port, String channel, String queueManager, String queueName, Long ccsid, String username, String password,
             Object data
@@ -160,4 +210,19 @@ public class IBMMQ {
         }
         return jmsTemplate;
     }
+
+
+
+    private static Map<String,Object> queryConnectionStr(String datasourceId) throws Exception {
+        List<Map<String, Object>> result = DATA_BASE.query(Config.getCenterConnectionStr(), """
+                select host,
+                password,
+                username,
+                from datasource
+                where datasourceid = ?""", datasourceId);
+        if (result.isEmpty()) {
+            throw new RuntimeException("数据源错误:没有找到数据源");
+        }
+        return result.stream().findFirst().get();
+    }
 }