Browse Source

upate http proxyconfig

wwd 3 years ago
parent
commit
4253536e0d

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

@@ -278,12 +278,11 @@ public class AmqpClient implements ApplicationRunner {
             hashtable.put("queue.QUEUE", "default");
             hashtable.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory");
             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);
+             //   context =new InitialContext(hashtable);
 //                JMSConnectionFactory cf1 = (JMSConnectionFactory) context.lookup("SBCF");
 //                Supplier<ProxyHandler> proxyHandlerSupplier =()->{
 //                  return new HttpProxyHandler(new InetSocketAddress(proxyhost,proxyport)) ;
@@ -291,31 +290,32 @@ public class AmqpClient implements ApplicationRunner {
 //                cf1.setExtension(JmsConnectionExtensions.PROXY_HANDLER_SUPPLIER.toString(),(connection1,remote)->{
 //                    return proxyHandlerSupplier;
 //                });
-
+                Supplier<ProxyHandler> proxyHandlerSupplier =()-> new HttpProxyHandler(new InetSocketAddress(proxyhost,proxyport));
                 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;
+//                    SocketAddress proxyAddress = new InetSocketAddress(proxyhost, proxyport);
+//                    Supplier<ProxyHandler> proxyHandlerFactory = () -> {
+//                        return new HttpProxyHandler(proxyAddress);
+//                    };
+                    return proxyHandlerSupplier;
                 });
                 connection = factory.createConnection(userName, password);
                 logger.info(">>>>>>>创建阿里iot通过招商代理访问互联网");
             }else{
+                 ConnectionFactory cf = (ConnectionFactory)context.lookup("SBCF");
                 // 创建连接。
                 connection= cf.createConnection(userName, password);
             }
 
-
+            Destination queue = (Destination)context.lookup("QUEUE");
             connections.add(connection);
 
             ((JmsConnection)connection).addConnectionListener(myJmsConnectionListener);
             // 创建会话。
             // Session.CLIENT_ACKNOWLEDGE: 收到消息后,需要手动调用message.acknowledge()。
             // Session.AUTO_ACKNOWLEDGE: SDK自动ACK(推荐)。
+           // Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
             Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
             connection.start();
             // 创建Receiver连接。
             MessageConsumer consumer = session.createConsumer(queue);