我正在尝试启动嵌入式群集配置,但我无法这样做。 我使用了hornetq示例中的集群示例。它有效,我不是使用嵌入式hornetq运行示例。我不能得到任何例外,但系统会死掉。
public class HornetQEmbedded {
private JMSServerManager jmsServerManager;
public HornetQEmbedded() {
}
public void start() {
try {
System.out.println("Starting Embedded HornetQ instance...");
// Retrieve configuration from xml file
FileConfiguration configuration = new FileConfiguration();
configuration.setConfigurationUrl("hornetq-configuration.xml");
configuration.start();
// Change acceptor configuration
Map<String, Object> acceptorParams = new HashMap<String, Object>();
acceptorParams.put(TransportConstants.PORT_PROP_NAME, "5446");
acceptorParams.put(TransportConstants.HOST_PROP_NAME, "0.0.0.0");
configuration.getAcceptorConfigurations().clear();
configuration.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName(), acceptorParams));
// Change connector configuration
Map<String, Object> connectorParams = new HashMap<String, Object>();
connectorParams.put(TransportConstants.PORT_PROP_NAME, "5446");
connectorParams.put(TransportConstants.HOST_PROP_NAME, "0.0.0.0");
configuration.getConnectorConfigurations().clear();
configuration.getConnectorConfigurations().put("netty", new TransportConfiguration(NettyAcceptorFactory.class.getName(), connectorParams));
// Create HornetQ server
HornetQServer server = HornetQServers.newHornetQServer(configuration);
server.getSecurityManager().addUser("guest", "guest");
server.getSecurityManager().setDefaultUser("guest");
server.getSecurityManager().addRole("guest", "guest");
// Load queues
jmsServerManager = new JMSServerManagerImpl(server, "hornetq-jms.xml");
jmsServerManager.setContext(null);
// Start server
jmsServerManager.start();
System.out.println("Waiting 5 second for embedded hornetq server to start...");
Thread.sleep(5000);
} catch (Exception e) {
System.out.println("Error starting Embedded HornetQ server: " + e.toString());
throw new RuntimeException(e);
}
}
}
这是HornetQ配置文件:
<configuration xmlns="urn:hornetq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
<paging-directory>data/paging</paging-directory>
<bindings-directory>data/bindings</bindings-directory>
<journal-directory>data/journal</journal-directory>
<journal-min-files>10</journal-min-files>
<large-messages-directory>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:0.0.0.0}"/>
<param key="port" value="${hornetq.remoting.netty.port:5444}"/>
</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:0.0.0.0}"/>
<param key="port" value="${hornetq.remoting.netty.port:5446}"/>
</acceptor>
</acceptors>
<!-- Clustering configuration -->
<broadcast-groups>
<broadcast-group name="my-broadcast-group">
<group-address>127.0.0.1</group-address> <!-- 231.7.7.7 -->
<group-port>5442</group-port> <!-- 9876 -->
<broadcast-period>100</broadcast-period>
<connector-ref>netty-connector</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="my-discovery-group">
<group-address>127.0.0.1</group-address> <!-- 231.7.7.7 -->
<group-port>5442</group-port> <!-- 9876 -->
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<address>jms</address>
<connector-ref>netty-connector</connector-ref>
<retry-interval>500</retry-interval>
<use-duplicate-detection>true</use-duplicate-detection>
<forward-when-no-consumers>true</forward-when-no-consumers>
<max-hops>1</max-hops>
<discovery-group-ref discovery-group-name="my-discovery-group"/>
</cluster-connection>
</cluster-connections>
<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>
<page-size-bytes>10485760</page-size-bytes>
<max-size-bytes>209715200</max-size-bytes>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
<address-full-policy>PAGE</address-full-policy>
</address-setting>
</address-settings>
</configuration>
答案 0 :(得分:2)
该示例是根据嵌入式用例编写的。服务器将作为应用程序的一部分。只要你的虚拟机死了,服务器就会死掉,这意味着什么。
在嵌入式服务器上,您应该启动一个线程并使其保持运行。
现在,作为一个黑客,尝试在开始时添加一个睡眠,但然后以适当的生命周期进行正确的应用。