Embedded HornetQ with persistence enabled fails to start with programmatic config

StackOverflow https://stackoverflow.com/questions/21397534

  •  03-10-2022
  •  | 
  •  

문제

I'm trying to run HornetQ embedded in my app. Configuring programatically results in this error.

So I've been trying to set config via xml file. The server starts successfully, but I get an error trying to create the client session.

Here's my code to starup

    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;

When it trys to connect, I get this error:

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>

도움이 되었습니까?

해결책

You have to test for the availability of AIO before configuring to AIO on your code.

Our server is doing this following check, for now you have to do the same on your embedded code. (We basically decided to respect what you choose, and issue an error if it wasn't available).

     boolean supportsAIO = AIOSequentialFileFactory.isSupported();

     if (supportsAIO)
     {
        config.setJournalType(JournalType.ASYNCIO);
     }
     else
     {
        config.setJournalType(JournalType.NIO);
     }

HornetQ has a JIRA open to improve this and make the switch automatically, but we had cases of users who actually wanted the error on embedded. It's hard to please everybody!

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top