HornetQ嵌入式集群配置
我正在尝试启动嵌入式集群配置,但无法这样做。 我使用了在 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>
I am trying to start an embedded cluster configuration but I wasn't able to do so.
I used the cluster example that was found on the hornetq examples. It works, I aren't to run the examples using an embedded hornetq. I can't get any exception but the system dies.
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);
}
}
}
And this is the HornetQ configuration file:
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该示例是根据嵌入式用例编写的。服务器将作为应用程序的一部分存在。这意味着只要你的虚拟机死了,服务器就会死。
在嵌入式服务器上,您应该启动一个线程并使其保持运行。
现在作为一个黑客,尝试在启动结束时添加睡眠,然后使用适当的生命周期创建适当的应用程序。
The example was written thinking on the embedded use case.. The server will live as part of your application. What means as long as your VM dies, the server will die.
On an embedded server, you are supposed to start a thread and leave it running.
As a hack now, try adding a sleep at the end of your start, but then make your proper application with a proper life cycle.