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