如何将代理设置为ActiveMQConnectionFactory以发送消息

时间:2016-06-03 21:14:19

标签: spring activemq

我使用spring activemq将jms消息发送到activemq消息队列。 消息队列是在远程服务器上创建的。我必须设置代理以从本地计算机到达该消息队列服务器。

任何人都可以帮我解决如何将代理添加到activemqConnectionFactory类。

我尝试使用HttpClientTransportProxyConnectorNetworkConnector类设置代理网址,但我不确定如何将这些添加到activemqconnectionFactory

请在下面找到详细信息:

message.queue.broker.url=ssl://<HOSTNAME>:61617

HttpClientTransport httpClientTransport = new HttpClientTransport(null, new URI(brokerUrl));
httpClientTransport.setProxyHost("<proxyHost>");
httpClientTransport.setProxyPort(3128);
httpClientTransport.start();

ProxyConnector proxy = new ProxyConnector();
proxy.setBind(new URI(brokerUrl));
proxy.setRemote(new URI(brokerUrl));
proxy.start();

NetworkConnector netConnector = new NetworkConnector() {
};
netConnector.setBrokerURL(brokerUrl);
netConnector.start();


ActiveMQConnectionFactory activeMQConnectionfactory = new ActiveMQConnectionFactory(userName, password, brokerUrl);

CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(activeMQConnectionfactory);
cachingConnectionFactory.setSessionCacheSize(50);

ActiveMQQueue activeMqQueue = new ActiveMQQueue(destination);

jmsTemplate = new JmsTemplate(sslConnectionFactory);
jmsTemplate.setDefaultDestination(activeMqQueue);

@Override
public void sendMessage(final String text) {
    // TODO Auto-generated method stub
    this.jmsTemplate.send(new MessageCreator() {
        @Override
        public Message createMessage(Session session) throws JMSException {
            Message message = session.createTextMessage(text);
            return message;
        }
    });
}

当我运行上面的代码时,我得到ConnectionTimedOutException:

  

引起:javax.jms.JMSException:无法连接到代理URL:ssl://:61617。原因:java.net.SocketTimeoutException:连接超时

我也试过

ssl://<URL>?transport.proxyHost=<PROXYHOST>amp;transport.proxyPort=3128

先谢谢。

0 个答案:

没有答案