java - 启用持久性的嵌入式 HornetQ 无法通过编程配置启动

标签 java hornetq

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

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

这是我的启动代码

    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>

最佳答案

在代码上配置 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

关于java - 启用持久性的嵌入式 HornetQ 无法通过编程配置启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21397534/

相关文章:

java - 使用反射查找方法是否重载

java - 如何使用 Project Tango 拍摄高分辨率照片并同时感测深度

java - 具有返回值的模板方法

websocket - 在 Wildfly 9 中通过 websocket 配置 STOMP

HornetQ (Jboss EAP 6.3) 和 Jboss 消息传递 (Jboss 4.2.2) 之间的 JMS 桥接器

java - 在运行时通过外部属性文件更改 logback 中的日志级别

java - 使用 gson 包解析嵌套的 json 结构

java - 我可以存储和读取 STOMP 队列/主题中的消息吗?

java - 为什么 Direct ByteBuffer 在 HornetQ 服务器上不断增加导致 OOM?