【问题标题】:Embedded HornetQ with persistence enabled fails to start with programmatic config启用持久性的嵌入式 HornetQ 无法以编程配置启动
【发布时间】:2014-02-19 06:37:11
【问题描述】:

我正在尝试运行嵌入在我的应用程序中的 HornetQ。以编程方式配置会导致 this 错误。

所以我一直在尝试通过 xml 文件设置配置。服务器成功启动,但尝试创建客户端会话时出现错误。

这是我的启动代码

    ClientSession session = null;
    try {
        EmbeddedHornetQ embedded = new EmbeddedHornetQ();
        try {
            embedded.start();
        } catch (Exception ex) {
            log.error("Error starting MQServer", ex);
            throw new RuntimeException(ex);
        }
        ClientSessionFactory sessionFactory =  HornetQClient.createServerLocatorWithoutHA(
                new TransportConfiguration(
                        InVMConnectorFactory.class.getName())).createSessionFactory();
        session = sessionFactory.createSession();
        final String queueName = "queue.exampleQueue";
        session.createQueue(queueName, queueName, true);

    }catch(Exception ex) {
        log.error("error", ex);
    }
    return session;

当它尝试连接时,我收到此错误:

WARNING: AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal
Jan 27, 2014 9:13:49 PM org.hornetq.core.logging.impl.JULLogDelegate info
INFO: live server is starting with configuration HornetQ Configuration (clustered=false,backup=false,sharedStore=true,journalDirectory=../data/journal,bindingsDirectory=../data/bindings,largeMessagesDirectory=../data/large-messages,pagingDirectory=../data/paging)
Jan 27, 2014 9:13:49 PM org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Waiting to obtain live lock
Jan 27, 2014 9:13:49 PM org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Using NIO Journal
Jan 27, 2014 9:13:49 PM org.hornetq.core.logging.impl.JULLogDelegate warn
WARNING: Security risk! It has been detected that the cluster admin user and password have not been changed from the installation default. Please see the HornetQ user guide, cluster chapter, for instructions on how to do this.
Jan 27, 2014 9:13:49 PM org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Waiting to obtain live lock
Jan 27, 2014 9:13:49 PM org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Live Server Obtained live lock
Jan 27, 2014 9:13:50 PM org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5445 for CORE protocol
Jan 27, 2014 9:13:50 PM org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Started Netty Acceptor version 3.2.3.Final-r${buildNumber} localhost:5455 for CORE protocol
Jan 27, 2014 9:13:50 PM org.hornetq.core.logging.impl.JULLogDelegate info
INFO: Server is now live
Jan 27, 2014 9:13:50 PM org.hornetq.core.logging.impl.JULLogDelegate info
INFO: HornetQ Server version 2.2.5.Final (HQ_2_2_5_FINAL_AS7, 121) [8d37d5e1-87d4-11e3-80c2-a5588295b5e6] started
Jan 27, 2014 9:13:50 PM org.hornetq.core.logging.impl.JULLogDelegate warn
WARNING: Tried 1 times to connect. Now giving up on reconnecting it.
2014-01-27 21:13:50,818 ERROR c.b.o.r.AppConfigModule [main] error
org.hornetq.api.core.HornetQException: Cannot connect to server(s). Tried with all     available servers.
    at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:619) ~[hornetq-core-2.2.5.Final.jar:?]

hornetq-configuration.xml:

<configuration xmlns="urn:hornetq"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="urn:hornetq/schema/hornetq-configuration.xsd">

<paging-directory>${data.dir:../data}/paging</paging-directory>

<bindings-directory>${data.dir:../data}/bindings</bindings-directory>

<journal-directory>${data.dir:../data}/journal</journal-directory>

<journal-min-files>10</journal-min-files>

<large-messages-directory>${data.dir:../data}/large-messages</large-messages-directory>

<connectors>
    <connector name="netty">
        <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
        <param key="host"  value="${hornetq.remoting.netty.host:localhost}"/>
        <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
    </connector>

    <connector name="netty-throughput">
        <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
        <param key="host"  value="${hornetq.remoting.netty.host:localhost}"/>
        <param key="port"  value="${hornetq.remoting.netty.batch.port:5455}"/>
        <param key="batch-delay" value="50"/>
    </connector>
</connectors>

<acceptors>
    <acceptor name="netty">
        <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
        <param key="host"  value="${hornetq.remoting.netty.host:localhost}"/>
        <param key="port"  value="${hornetq.remoting.netty.port:5445}"/>
    </acceptor>

    <acceptor name="netty-throughput">
        <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
        <param key="host"  value="${hornetq.remoting.netty.host:localhost}"/>
        <param key="port"  value="${hornetq.remoting.netty.batch.port:5455}"/>
        <param key="batch-delay" value="50"/>
        <param key="direct-deliver" value="false"/>
    </acceptor>
</acceptors>

<security-settings>
    <security-setting match="#">
        <permission type="createNonDurableQueue" roles="guest"/>
        <permission type="deleteNonDurableQueue" roles="guest"/>
        <permission type="consume" roles="guest"/>
        <permission type="send" roles="guest"/>
    </security-setting>
</security-settings>

<address-settings>
    <!--default for catch all-->
    <address-setting match="#">
        <dead-letter-address>jms.queue.DLQ</dead-letter-address>
        <expiry-address>jms.queue.ExpiryQueue</expiry-address>
        <redelivery-delay>0</redelivery-delay>
        <max-size-bytes>10485760</max-size-bytes>
        <message-counter-history-day-limit>10</message-counter-history-day-limit>
        <address-full-policy>BLOCK</address-full-policy>
    </address-setting>
</address-settings>

【问题讨论】:

    标签: java hornetq


    【解决方案1】:

    在您的代码上配置为 AIO 之前,您必须测试 AIO 的可用性。

    我们的服务器正在执行以下检查,现在您必须对嵌入式代码执行相同的操作。 (我们基本上决定尊重您的选择,如果不可用则发出错误)。

         boolean supportsAIO = AIOSequentialFileFactory.isSupported();
    
         if (supportsAIO)
         {
            config.setJournalType(JournalType.ASYNCIO);
         }
         else
         {
            config.setJournalType(JournalType.NIO);
         }
    

    HornetQ 有一个开放的 JIRA 来改进这一点并自动进行切换,但我们有一些用户实际上希望嵌入错误。很难取悦所有人!

    https://issues.jboss.org/browse/HORNETQ-1307

    【讨论】:

    • 谢谢!我也在票中添加了一个链接。
    • 我刚刚对 2.4.2 进行了修复(我写这篇文章时刚刚发布了 2.4.1)...我曾经遇到过一些用户希望过去不尊重失败但那是少数..所以我现在正在为嵌入式的未来版本更改该指令。
    • 很好,再次感谢!当它可用时,我应该能够切换到 2.4.2,因为我刚刚开始在新项目中使用 hornetq。
    猜你喜欢
    • 1970-01-01
    • 2013-12-27
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-22
    相关资源
    最近更新 更多