Java 地址已与HornetQ中的NettyAcceptor一起使用

Java 地址已与HornetQ中的NettyAcceptor一起使用,java,spring,netty,hornetq,Java,Spring,Netty,Hornetq,我正在开发一个Spring应用服务器,将HotnetQ嵌入到pubsub服务中。下面我将向manager HornetQ server介绍下一个类 但是,当我部署我的应用程序时,在tomcat控制台中会出现下一个错误 我一直在更改Netty接受器端口号,但问题仍然存在,若我使用其他接受器而不是Netty,它工作正常,但我对Netty接受器类型感兴趣 Setting ServerMQ configuration... Initializing ServerMQ... mar 12, 2014 1:

我正在开发一个Spring应用服务器,将HotnetQ嵌入到pubsub服务中。下面我将向manager HornetQ server介绍下一个类

但是,当我部署我的应用程序时,在tomcat控制台中会出现下一个错误

我一直在更改Netty接受器端口号,但问题仍然存在,若我使用其他接受器而不是Netty,它工作正常,但我对Netty接受器类型感兴趣

Setting ServerMQ configuration...
Initializing ServerMQ...
mar 12, 2014 1:42:44 PM org.hornetq.core.server.impl.HornetQServerImpl start
INFO: HQ221000: live server is starting with configuration HornetQ Configuration (clustered=false,backup=false,sharedStore=true,journalDirectory=data/journal,bindingsDirectory=data/bindings,largeMessagesDirectory=data/largemessages,pagingDirectory=data/paging)
mar 12, 2014 1:42:44 PM org.hornetq.core.server.impl.HornetQServerImpl initialisePart1
WARN: HQ222007: Security risk! HornetQ is running with the default cluster admin user and default password. Please see the HornetQ user guide, cluster chapter, for instructions on how to change this.
mar 12, 2014 1:42:44 PM org.hornetq.core.remoting.server.impl.RemotingServiceImpl <init>
INFO: HQ221043: Adding protocol support CORE
ServerMQ initialized!
mar 12, 2014 1:42:44 PM org.hornetq.core.server.impl.HornetQServerImpl$SharedNothingLiveActivation run
ERROR: HQ224000: Failure in initialisation
java.net.BindException: Address already in use: bind
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:444)
    at sun.nio.ch.Net.bind(Net.java:436)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:102)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:479)
    at io.netty.channel.DefaultChannelPipeline$HeadHandler.bind(DefaultChannelPipeline.java:1000)
    at io.netty.channel.DefaultChannelHandlerContext.invokeBind(DefaultChannelHandlerContext.java:457)
    at io.netty.channel.DefaultChannelHandlerContext.bind(DefaultChannelHandlerContext.java:442)
    at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:842)
    at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:194)
    at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:331)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
    at java.lang.Thread.run(Thread.java:744)

mar 12, 2014 1:42:44 PM org.hornetq.core.server.impl.HornetQServerImpl start
INFO: HQ221001: HornetQ Server version 2.4.1.Final (Fast Hornet, 124) [a681c9b2-a83a-11e3-b8ef-531df38c9cfa]
正在设置服务器MQ配置。。。
正在初始化服务器MQ。。。
2014年3月12日下午1:42:44 org.hornetq.core.server.impl.hornetqserver impl启动
信息:HQ221000:live server正在以配置HornetQ配置启动(clustered=false,backup=false,sharedStore=true,journalDirectory=data/journal,bindingsDirectory=data/bindings,LargeMessageDirectory=data/largemessages,pagingDirectory=data/paging)
2014年3月12日下午1:42:44 org.hornetq.core.server.impl.hornetqserver impl initialisePart1
警告:HQ222007:安全风险!HornetQ使用默认群集管理用户和默认密码运行。请参阅《HornetQ用户指南》中的群集一章,了解有关如何更改此设置的说明。
2014年3月12日下午1:42:44 org.hornetq.core.remoting.server.impl.remotingserviceinpl
信息:HQ221043:添加协议支持核心
服务器MQ已初始化!
2014年3月12日下午1:42:44 org.hornetq.core.server.impl.hornetqserver impl$SharedNothingLiveActivation运行
错误:HQ224000:初始化失败
java.net.BindException:地址已在使用中:bind
位于sun.nio.ch.Net.bind0(本机方法)
位于sun.nio.ch.Net.bind(Net.java:444)
位于sun.nio.ch.Net.bind(Net.java:436)
位于sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
位于sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
位于io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:102)
在io.netty.channel.AbstractChannel$AbstractSafe.bind(AbstractChannel.java:479)
位于io.netty.channel.DefaultChannelPipeline$HeadHandler.bind(DefaultChannelPipeline.java:1000)
位于io.netty.channel.DefaultChannelHandlerContext.invokeBind(DefaultChannelHandlerContext.java:457)
位于io.netty.channel.DefaultChannelHandlerContext.bind(DefaultChannelHandlerContext.java:442)
位于io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:842)
位于io.netty.channel.AbstractChannel.bind(AbstractChannel.java:194)
位于io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:331)
位于io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
位于io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)
位于io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
运行(Thread.java:744)
2014年3月12日下午1:42:44 org.hornetq.core.server.impl.hornetqserver impl启动
信息:HQ221001:HornetQ服务器版本2.4.1.Final(Fast Hornet,124)[a681c9b2-a83a-11e3-b8ef-531df38c9cfa]
这是我的类实现

@Component(value = "serverMQ")
public class ServerMQ extends EmbeddedHornetQ {

    // Server config.
    private Configuration config;

    private ClientSessionFactory clientSessionFactory;

    public ServerMQ() {

        System.out.println("Setting ServerMQ configuration...");

        // Instantiate server config.
        this.config = new ConfigurationImpl();

        // Server has persistence for messages.
        this.config.setPersistenceEnabled(false);

        // Server has user security authentication.
        this.config.setSecurityEnabled(false);

        Map<String, Object> nettyAcceptorParams = new HashMap<String, Object>();
        nettyAcceptorParams.put(TransportConstants.HOST_PROP_NAME, "localhost");
        nettyAcceptorParams.put(TransportConstants.PORT_PROP_NAME, 5555);

        this.config.getAcceptorConfigurations().clear();

        this.config.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName(), nettyAcceptorParams));
    }

    @PostConstruct
    public void init() {

        try {

            System.out.println("Initializing ServerMQ...");

            this.setConfiguration(this.config);
            this.start();

            System.out.println("ServerMQ initialized!");
        } catch (Exception ex) {

            System.err.println("ServerMQ initializing error:\n" + ex.getMessage());
        }
    }

}
@组件(value=“serverMQ”)
公共类ServerMQ扩展了EmbeddedHornetQ{
//服务器配置。
私有配置;
私人客户端会话工厂客户端会话工厂;
公共服务器MQ(){
System.out.println(“设置服务器MQ配置…”);
//实例化服务器配置。
this.config=new configurationmpl();
//服务器具有消息的持久性。
this.config.setPersistenceEnabled(false);
//服务器具有用户安全身份验证。
this.config.setSecurityEnabled(false);
Map nettyAcceptorParams=新HashMap();
nettyAcceptorParams.put(TransportConstants.HOST_PROP_NAME,“localhost”);
nettyAcceptorParams.put(TransportConstants.PORT_PROP_NAME,5555);
这个.config.getAcceptorConfiguration().clear();
这个.config.getAcceptorConfiguration().add(新的传输配置(NettyAcceptorFactory.class.getName(),nettyAcceptorParams));
}
@施工后
公共void init(){
试一试{
System.out.println(“初始化服务器MQ…”);
this.setConfiguration(this.config);
这个。start();
System.out.println(“服务器MQ已初始化!”);
}捕获(例外情况除外){
System.err.println(“服务器MQ初始化错误:\n”+ex.getMessage());
}
}
}
@Clebert建议之后,我已经更改了我的ServerMQ类,以尝试实现pubsub服务的新方法,如下所示。。。同样的问题

@Component(value = "serverMQ")
public class ServerMQ {

    // Server config.
    private Configuration config;

    // HornetQ Server
    private EmbeddedHornetQ mQServer;

    private ClientSessionFactory clientSessionFactory;
public ServerMQ() {

    System.out.println("Setting ServerMQ configuration...");

    // Instantiate server config.
    this.config = new ConfigurationImpl();

    // Server has persistence for messages.
    this.config.setPersistenceEnabled(false);

    // Server has user security authentication.
    this.config.setSecurityEnabled(false);

    Map<String, Object> nettyAcceptorAttrs = new HashMap<String, Object>();
    nettyAcceptorAttrs.put(TransportConstants.HOST_PROP_NAME, "localhost");
    nettyAcceptorAttrs.put(TransportConstants.PORT_PROP_NAME, 5555);

    /*
     HashSet<TransportConfiguration> transports = new HashSet<TransportConfiguration>();
     transports.add(new TransportConfiguration(NettyAcceptorFactory.class.getName(), nettyAcceptorParams));
     transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
     */

    this.config.getAcceptorConfigurations().clear();

    this.config.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName(), nettyAcceptorAttrs));

    this.init2();
}

public void init2() {

    try {

        System.out.println("Initializing ServerMQ...");

        this.mQServer = new EmbeddedHornetQ();

        this.mQServer.setConfiguration(this.config);
        this.mQServer.start();
        /*
         this.clientSessionFactory = HornetQClient.createServerLocatorWithoutHA(
         new TransportConfiguration(
         InVMConnectorFactory.class.getName())).createSessionFactory();
         */
        System.out.println("ServerMQ initialized!");
    } catch (Exception ex) {

        System.err.println("ServerMQ initializing error:\n" + ex.getMessage());
    }
}
@组件(value=“serverMQ”)
公共类服务器MQ{
//服务器配置。
私有配置;
//HornetQ服务器
专用嵌入式HornetQ mQServer;
私人客户端会话工厂客户端会话工厂;
公共服务器MQ(){
System.out.println(“设置服务器MQ配置…”);
//实例化服务器配置。
this.config=new configurationmpl();
//服务器具有消息的持久性。
this.config.setPersistenceEnabled(false);
//服务器具有用户安全身份验证。
this.config.setSecurityEnabled(false);
Map nettyAcceptorAttrs=newhashmap();
nettyAcceptorAttrs.put(TransportConstants.HOST_PROP_NAME,“localhost”);
nettyAcceptorRatters.put(TransportConstants.PORT_PROP_NAME,5555);
/*
HashSet transports=新HashSet();
添加(新的TransportConfiguration(NettyAcceptorFactory.class.getName(),nettyAcceptorParams));
添加(新的传输配置(InVMAcceptorFactory.class.getName());
*/
这个.config.getAcceptorConfiguration().clear();
这个.config.getAcceptorConfiguration().add(新的传输配置(NettyAcceptorFactory.class.getName(),nettyAcceptorRatters));
this.init2();
}
public void init2(){
试一试{
System.out.println(“初始化服务器MQ…”);
this.mQServer=new EmbeddedHornetQ();
this.mQServer.setConfiguration(this.config);
package org.hornetq.tests.integration;

import java.util.HashMap;
import java.util.Map;

import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSessionFactory;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory;
import org.hornetq.core.remoting.impl.netty.TransportConstants;
import org.hornetq.core.server.embedded.EmbeddedHornetQ;

public class ServerMQ
{

   // Server config.
   private Configuration config;

   // HornetQ Server
   private EmbeddedHornetQ mQServer;

   private ClientSessionFactory clientSessionFactory;

   public ServerMQ()
   {

      System.out.println("Setting ServerMQ configuration...");

      // Instantiate server config.
      this.config = new ConfigurationImpl();

      // Server has persistence for messages.
      this.config.setPersistenceEnabled(false);

      // Server has user security authentication.
      this.config.setSecurityEnabled(false);

      Map<String, Object> nettyAcceptorAttrs = new HashMap<String, Object>();
      nettyAcceptorAttrs.put(TransportConstants.HOST_PROP_NAME, "localhost");
      nettyAcceptorAttrs.put(TransportConstants.PORT_PROP_NAME, 5555);

    /*
     HashSet<TransportConfiguration> transports = new HashSet<TransportConfiguration>();
     transports.add(new TransportConfiguration(NettyAcceptorFactory.class.getName(), nettyAcceptorParams));
     transports.add(new TransportConfiguration(InVMAcceptorFactory.class.getName()));
     */

      this.config.getAcceptorConfigurations().clear();

      this.config.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName(), nettyAcceptorAttrs));

      this.init2();
   }

   public void init2()
   {

      try
      {

         System.out.println("Initializing ServerMQ...");

         this.mQServer = new EmbeddedHornetQ();

         this.mQServer.setConfiguration(this.config);
         this.mQServer.start();
        /*
         this.clientSessionFactory = HornetQClient.createServerLocatorWithoutHA(
         new TransportConfiguration(
         InVMConnectorFactory.class.getName())).createSessionFactory();
         */
         System.out.println("ServerMQ initialized!");
      }
      catch (Exception ex)
      {

         System.err.println("ServerMQ initializing error:\n" + ex.getMessage());
      }
   }
   public static void main(String arg[])
   {
      ServerMQ mq = new ServerMQ();

      try
      {
         Thread.sleep(10000);
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }

}