|
@@ -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);
|