SSL启用HornetQ客户端

时间:2014-10-29 20:44:02

标签: ssl jms jndi hornetq

我使用JNDI编写了一个hornetQ客户端。现在hornetQ服务器已启用SSL但我无法连接到它。请在下面找到我的配置文件并告诉我我缺少的内容。我正在使用JNP进行命名。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jms="http://www.springframework.org/schema/jms"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans      
                http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/tx 
                http://www.springframework.org/schema/tx/spring-tx.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/jms
                http://www.springframework.org/schema/jms/spring-jms.xsd">
    <!-- import resource="classpath:spring-common.xml" /-->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 
        <property name="locations">
            <list>
                <value>classpath:jndi.properties</value>
            </list>
        </property>
    </bean>

    <bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
        <property name="environment">
            <props>
                <prop key="java.naming.provider.url">${java.naming.provider.url}</prop>
                <prop key="java.naming.factory.initial">${java.naming.factory.initial}</prop>
                <prop key="java.naming.factory.url.pkgs">${java.naming.factory.url.pkgs}</prop>
                <prop key="jboss.naming.client.remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED">${ssl.enabled}</prop>
                <prop key="jboss.naming.client.connect.options.org.xnio.Options.SSL_STARTTLS">${ssl.starttls}</prop>
            </props>
        </property>
    </bean>

    <bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate" ref ="jndiTemplate"/>
        <property name="jndiName" value="ConnectionFactory"/>
    </bean>

    <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory" ref="connectionFactory"/>
        <property name="defaultDestination" ref="destination"/>
        <property name="pubSubDomain" value="true"/>
        <property name="deliveryPersistent" value="true"/>
        <property name="deliveryMode" value="2"/>
    </bean>

    <bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiTemplate" ref="jndiTemplate"/>
        <property name="jndiName" value="ACS_BOOT"/>
    </bean>

    <!-- Listener Asynchronous -->
    <bean id="acsBootListener" class="com.viasat.nbn.nms.acsjmssubscriber.AcsBootListener"/>

    <jms:listener-container concurrency="5-10">
                 <jms:listener destination="ACS_BOOT" ref="acsBootListener"/>
    </jms:listener-container>

</beans>

我的Main课程看起来像这样:

public class AcsBootConsumer {
private String keyStore, ksPassword, trustStore, tsPassword;

public static void main(String[] args) throws JMSException{
    ApplicationContext context = new ClassPathXmlApplicationContext("spring-cred.xml");
    AcsBootConsumer acsBootConsumer = (AcsBootConsumer)context.getBean("acsBootConsumer");
    System.setProperty("javax.net.ssl.keyStore",acsBootConsumer.keyStore);
    System.setProperty("javax.net.ssl.keyStorePassword", acsBootConsumer.ksPassword);
    System.setProperty("javax.net.ssl.trustStore",acsBootConsumer.trustStore);
    System.setProperty("javax.net.ssl.trustStorePassword", acsBootConsumer.tsPassword);
    ClassPathXmlApplicationContext context1 = new ClassPathXmlApplicationContext("spring-app.xml");
    JndiTemplate jndiTemplate = (JndiTemplate)context1.getBean("jndiTemplate");
    System.out.println("AcsBootConsumer connected to " + jndiTemplate.getEnvironment().getProperty("java.naming.provider.url"));    
}

我无法理解我哪里出错了。我收到以下错误:

SEVERE: Could not refresh JMS Connection for destination 'ACS_BOOT' - retrying in 5000 ms. Cause: Failed to create session factory; nested exception is HornetQException[errorType=NOT_CONNECTED message=HQ119007: Cannot connect to server(s). Tried with all available servers.]

0 个答案:

没有答案