开发者

How to change the port in an embedded HornetQ programmatically

I want to change the default port in my embedded HornetQ. This works when done in the hornetq-configuration.xml file:

<acceptors>
  <acceptor name="netty-acceptor">
    <factory-class>org.hornetq.integration.transports.netty.NettyAcceptorFactory</factory-class>
    <param key="port" value="6446"/>
  </acceptor>
</acceptors>

But changing programmatically does not. I load the configuration from file, and try to override, without success - here is what I try:

// Load configuration
FileConfiguration configuration = new FileConfiguration()开发者_如何学Python;
configuration.setConfigurationUrl("hornetq-configuration.xml");

// Prepare configuration objects
String netty = NettyAcceptorFactory.class.getName();
Map<String, Object> transportParams = new HashMap<String, Object>();
transportParams.put(TransportConstants.HOST_PROP_NAME, "localhost");
transportParams.put(TransportConstants.PORT_PROP_NAME, 6446);
TransportConfiguration transpConf = new TransportConfiguration(netty, transportParams);

// add configuration (clearing before didn't helped either))
configuration.getAcceptorConfigurations().add(transpConf);
configuration.start(); // moving this right after the setting the file didn't helped

// start server
HornetQServer server = HornetQServers.newHornetQServer(configuration);
JMSServerManager jmsServerManager = new JMSServerManagerImpl(server, "hornetq-jms.xml");
jmsServerManager.setContext(null);
jmsServerManager.start();

Any ideas? Thanks


This didn't work because the configuration.start() will override anything you added.

You should be able to do something like this:

FileConfiguration configuration = new FileConfiguration();
configuration.setConfigurationUrl("hornetq-configuration.xml");

configuration.start(); // <<<-----------------

// Prepare configuration objects
String netty = NettyAcceptorFactory.class.getName();
Map<String, Object> transportParams = new HashMap<String, Object>();
transportParams.put(TransportConstants.HOST_PROP_NAME, "localhost");
transportParams.put(TransportConstants.PORT_PROP_NAME, 6446);
TransportConfiguration transpConf = new TransportConfiguration(netty, transportParams);

configuration.getAcceptorconfigurations().clear(); // <<<-----------------

// add configuration
configuration.getAcceptorConfigurations().add(transpConf);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜