Prechádzať zdrojové kódy

update alibaba proxy

wwd 3 rokov pred
rodič
commit
84d47c3ace

+ 24 - 0
src/main/java/com/persagy/ztkencryptdecodedata/alibabaiot/AmqpClient.java

@@ -1,7 +1,10 @@
 package com.persagy.ztkencryptdecodedata.alibabaiot;
 
+import io.netty.handler.proxy.HttpProxyHandler;
+import io.netty.handler.proxy.ProxyHandler;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.qpid.jms.JmsConnection;
+import org.apache.qpid.jms.JmsConnectionExtensions;
 import org.apache.qpid.jms.JmsConnectionListener;
 import org.apache.qpid.jms.message.JmsInboundMessageDispatch;
 import org.slf4j.Logger;
@@ -20,6 +23,7 @@ import javax.crypto.spec.SecretKeySpec;
 import javax.jms.*;
 import javax.naming.Context;
 import javax.naming.InitialContext;
+import java.net.InetSocketAddress;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Hashtable;
@@ -28,6 +32,7 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Supplier;
 
 @Component
 @Order(value = 1)
@@ -54,6 +59,12 @@ public class AmqpClient implements ApplicationRunner {
     //${YourHost}为接入域名,请参见AMQP客户端接入说明文档。
     @Value("${alibaba.iot.host}")
     private  String host ;
+    @Value("${alibaba.iot.proxy}")
+    private  boolean proxy;
+    @Value("${alibaba.iot.proxyhost}")
+    private  String proxyhost;
+    @Value("${alibaba.iot.proxyport}")
+    private  Integer proxyport;
 
 
 
@@ -268,6 +279,19 @@ public class AmqpClient implements ApplicationRunner {
             Context context = new InitialContext(hashtable);
             ConnectionFactory cf = (ConnectionFactory)context.lookup("SBCF");
             Destination queue = (Destination)context.lookup("QUEUE");
+
+            if (proxy){
+                context =new InitialContext(hashtable);
+                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;
+//                });
+            }
+
             // 创建连接。
             Connection connection = cf.createConnection(userName, password);
             connections.add(connection);

+ 3 - 0
src/main/resources/application-prod.yml

@@ -60,6 +60,9 @@ spring:
 
 alibaba:
   iot:
+    proxy: true
+    proxyhost: 100.70.99.2
+    proxyport: 3128
     accessKey: "LTAI4G17bcrwA5wexPRNAbNw"
     accessSecret: "LpbFTkw09VxAYFIDw9fvkwES6Lkz2i"
     consumerGroupId: "DEFAULT_GROUP"

+ 5 - 2
src/main/resources/application-uat.yml

@@ -13,7 +13,7 @@ rsa:
 
 spring:
   kafka:
-    bootstrap-servers:  192.168.2.128:9092,192.168.2.128:9093,192.168.2.128:9094
+    bootstrap-servers:  100.76.48.6:4309,100.76.48.7:4309,100.76.48.8:4309
     producer:
       retries: 10000
       batch-size: 16384
@@ -36,7 +36,7 @@ spring:
 
 
     consumer:
-      bootstrap-servers: 192.168.2.128:9092,192.168.2.128:9093,192.168.2.128:9094
+      bootstrap-servers: 100.76.48.6:4309,100.76.48.7:4309,100.76.48.8:4309
       group-id: _consumer_
       auto-offset-reset: earliest
       key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
@@ -60,6 +60,9 @@ spring:
 
 alibaba:
   iot:
+    proxy: true
+    proxyhost: 100.70.99.2
+    proxyport: 3128
     accessKey: "LTAI4G17bcrwA5wexPRNAbNw"
     accessSecret: "LpbFTkw09VxAYFIDw9fvkwES6Lkz2i"
     consumerGroupId: "DEFAULT_GROUP"