2014-01-28 39 views
1

我試圖在我的應用程序中運行嵌入的HornetQ。以編程方式配置會導致this錯誤。已啓用持久性的嵌入式HornetQ無法以編程配置開始

所以我一直在嘗試通過xml文件設置配置。服務器啓動成功,但嘗試創建客戶端會話時出現錯誤。

這裏是我的代碼的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; 

當改掉連接時,我得到這個錯誤:

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> 

回答

0

你必須測試在您的代碼上配置爲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

+0

謝謝!我在門票中添加了一個鏈接。 –

+0

我剛剛爲2.4.2(剛剛發佈時2.4.1當我寫這個)提交了一個修復程序... ... 我曾經有過用戶希望失敗的過去受到尊重的情況,但這一直是少數..所以我現在正在改變這個指令,爲嵌入式的未來版本。 –

+0

不錯,再次感謝!我應該能夠在2.4.2可用時切換,因爲我剛開始在新項目中使用hornetq。 –

相關問題