Browse Source

ibmmq添加datasourceid参数方法

andy 1 year ago
parent
commit
58282e5e7b
1 changed files with 67 additions and 2 deletions
  1. 67 2
      src/main/java/com/scbfkj/uni/process/IBMMQ.java

+ 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.io.IOException;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 
 
 
 
 public class IBMMQ {
 public class IBMMQ {
 
 
-
+    private static final DataBase DATA_BASE = new DataBase();
     private JmsTemplate jmsTemplate = null;
     private JmsTemplate jmsTemplate = null;
 
 
     private final ObjectMapper mapper = new ObjectMapper();
     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(
     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 {
             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 template = getJmsTemplate(host, port.intValue(), ccsid.intValue(), queueManager, channel, username, password);
 
 
-
         jmsTemplate.setReceiveTimeout(receiveTimeout);
         jmsTemplate.setReceiveTimeout(receiveTimeout);
         long maxSize = 100;
         long maxSize = 100;
         if (pollSize > 0) {
         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(
     public void sendMessage(
             String host, Long port, String channel, String queueManager, String queueName, Long ccsid, String username, String password,
             String host, Long port, String channel, String queueManager, String queueName, Long ccsid, String username, String password,
             Object data
             Object data
@@ -160,4 +210,19 @@ public class IBMMQ {
         }
         }
         return jmsTemplate;
         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();
+    }
 }
 }