Browse Source

update aliproxy logger info

wwd 3 years ago
parent
commit
6136bf4287

+ 23 - 9
src/main/java/com/persagy/ztkencryptdecodedata/alibabaiot/AmqpClient.java

@@ -17,13 +17,14 @@ import org.springframework.core.annotation.Order;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.stereotype.Component;
-
+import org.apache.qpid.jms.JmsConnectionFactory;
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 import javax.jms.*;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import java.net.InetSocketAddress;
+import java.net.SocketAddress;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Hashtable;
@@ -279,21 +280,34 @@ public class AmqpClient implements ApplicationRunner {
             Context context = new InitialContext(hashtable);
             ConnectionFactory cf = (ConnectionFactory)context.lookup("SBCF");
             Destination queue = (Destination)context.lookup("QUEUE");
-
+            Connection connection = null;
             if (proxy){
+                logger.info(">>>>进入代理服务处理方法");
                 context =new InitialContext(hashtable);
-                JMSConnectionFactory cf1 = (JMSConnectionFactory) context.lookup("SBCF");
-
-                Supplier<ProxyHandler> proxyHandlerSupplier =()->{
-                  return new HttpProxyHandler(new InetSocketAddress(proxyhost,proxyport)) ;
-                };
+//                JMSConnectionFactory cf1 = (JMSConnectionFactory) context.lookup("SBCF");
+//                Supplier<ProxyHandler> proxyHandlerSupplier =()->{
+//                  return new HttpProxyHandler(new InetSocketAddress(proxyhost,proxyport)) ;
+//                };
 //                cf1.setExtension(JmsConnectionExtensions.PROXY_HANDLER_SUPPLIER.toString(),(connection1,remote)->{
 //                    return proxyHandlerSupplier;
 //                });
+
+                JmsConnectionFactory factory = (JmsConnectionFactory) context.lookup("SBCF");
+                factory.setExtension(JmsConnectionExtensions.PROXY_HANDLER_SUPPLIER.toString(), (connection1, remote) -> {
+                    SocketAddress proxyAddress = new InetSocketAddress(proxyhost, proxyport);
+                    Supplier<ProxyHandler> proxyHandlerFactory = () -> {
+                        return new HttpProxyHandler(proxyAddress);
+                    };
+                    return proxyHandlerFactory;
+                });
+                connection = factory.createConnection(userName, password);
+                logger.info(">>>>>>>创建阿里iot通过招商代理访问互联网");
+            }else{
+                // 创建连接。
+                connection= cf.createConnection(userName, password);
             }
 
-            // 创建连接。
-            Connection connection = cf.createConnection(userName, password);
+
             connections.add(connection);
 
             ((JmsConnection)connection).addConnectionListener(myJmsConnectionListener);

+ 1 - 1
src/main/resources/application-prod.yml

@@ -61,7 +61,7 @@ spring:
 alibaba:
   iot:
     proxy: true
-    proxyhost: 100.70.99.2
+    proxyhost: "100.70.99.2"
     proxyport: 3128
     accessKey: "LTAI4G17bcrwA5wexPRNAbNw"
     accessSecret: "LpbFTkw09VxAYFIDw9fvkwES6Lkz2i"

+ 1 - 1
src/main/resources/application-uat.yml

@@ -61,7 +61,7 @@ spring:
 alibaba:
   iot:
     proxy: true
-    proxyhost: 100.70.99.2
+    proxyhost: "100.70.99.2"
     proxyport: 3128
     accessKey: "LTAI4G17bcrwA5wexPRNAbNw"
     accessSecret: "LpbFTkw09VxAYFIDw9fvkwES6Lkz2i"