2016-08-05 98 views
0

我是ActiveMQ中的新成员,我需要创建spring引导应用程序,其中包含publis activeMQ队列。因此,我创建的简单SpringBoot应用Spring Boot ActiveMQ - 端口已在使用中:1099

@SpringBootApplication 
@EnableJms 
public class Application { 

    @Bean 
    JmsListenerContainerFactory<?> myJmsContainerFactory(ConnectionFactory connectionFactory) { 
     SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory(); 
     factory.setConnectionFactory(connectionFactory); 
     return factory; 
    } 

    public static void main(String[] args) { 
     FileSystemUtils.deleteRecursively(new File("activemq-data")); 
     // Launch the application 
     ApplicationContext context = SpringApplication.run(Application.class, args); 
     System.out.println(" ************************ Asyn queue start ************************ ");   
    } 
} 

然后,我创建了一个Listneres还有:

@Component 
public class Receiver { 

    @Autowired 
    ConfigurableApplicationContext context; 


    @JmsListener(destination = "mailbox-destination", containerFactory = "myJmsContainerFactory") 
    public void receiveMessageFromMailbox(String message) { 
     System.out.println("Received <" + message + "> mailbox"); 
     //context.close(); 
     FileSystemUtils.deleteRecursively(new File("activemq-data")); 
    } 

    @JmsListener(destination = "testqueue-destination", containerFactory = "myJmsContainerFactory") 
    public void receiveMessageFromTestQueue(String message) { 
     System.out.println("Received <" + message + "> testqueue"); 
     //context.close(); 
     FileSystemUtils.deleteRecursively(new File("activemq-data")); 
    } 
} 

后,我开始它,它看起来确定。

为了测试我创建了一个简单的测试:

public class Testing { 

    public static void main(String[] args) throws JMSException { 
     try { 
      // Create a ConnectionFactory 
      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); 
      // Create a Connection 
      Connection connection = connectionFactory.createConnection(); 
      connection.start(); 
      // Create a Session 
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 
      // Create the destination (Topic or Queue) 
      Destination destination = session.createQueue("testqueue-destination"); 
      // Create a MessageProducer from the Session to the Topic or Queue 
      MessageProducer producer = session.createProducer(destination); 
      producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 
      // Create a messages 
      String text = "Hello world! From: " + Thread.currentThread().getName() + " : "; 
      TextMessage message = session.createTextMessage(text); 
      // Tell the producer to send the message 
      System.out.println("Sent message: "+ message.hashCode() + " : " + Thread.currentThread().getName() + " : " + message); 
      producer.send(message); 
      // Clean up 
      session.close(); 
      connection.close(); 
     } catch (Exception e) { 
      System.out.println("Caught: " + e); 
      e.printStackTrace(); 
     } 
    } 
} 

但是当我运行Testing.main则错误发生:

[主要] DEBUG org.apache.activemq.broker.jmx.ManagementContext - 无法创建本地注册表 java.rmi.server.ExportException:端口已在使用中:1099;嵌套的异常是: java.net.BindException:已在使用的地址:JVM_Bind at sun.rmi.transport.tcp.TCPTransport.listen(TCPTransport.java:341) at sun.rmi.transport.tcp.TCPTransport.exportObject (TCPTransport.java:249) at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:411) at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:147) at sun.rmi .server.UnicastServerRef.exportObject(UnicastServerRef.java:208) at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:152) at sun.rmi.registry.RegistryImpl。(RegistryImpl.java:112) at java.rmi.registry.LocateRegistry.createRegistry(LocateRegistry.java:239) at org.apache.activemq.broker.jmx.ManagementCont ext.createConnector(ManagementContext.java:418) at org.apache.activemq.broker.jmx.ManagementContext.findTigerMBeanServer(ManagementContext.java:363) at org.apache.activemq.broker.jmx.ManagementContext.findMBeanServer(ManagementContext。的java:330) 在org.apache.activemq.broker.jmx.ManagementContext.getMBeanServer(ManagementContext.java:172) 在org.apache.activemq.broker.jmx.ManagementContext.start(ManagementContext.java:80) 在org.apache.activemq.broker.BrokerService.startManagementContext(BrokerService.java:2031) 在org.apache.activemq.broker.BrokerService.start(BrokerService.java:477)

我认为这个问题是测试方法。但我不知道什么是不正确的。有人可以帮助我吗?谢谢。

回答

0

您是否尝试运行netstart命令来检查端口是否正在使用?

对于linux netstat -pnlt | grep 1099

对于windows netstat -np TCP |找到“1099”

0

我知道该端口被SpringBoot应用程序使用。该SpringBoot应用程序启动后,则下面的日志打印:

[   main] o.apache.activemq.broker.BrokerService : Using Persistence Adapter: MemoryPersistenceAdapter 
[   main] o.apache.activemq.broker.BrokerService : ActiveMQ 5.4.2 JMS Message Broker (localhost) is starting 
[   main] o.apache.activemq.broker.BrokerService : For help or more information please see: http://activemq.apache.org/ 
[ JMX connector] o.a.a.broker.jmx.ManagementContext  : JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi 
[   main] o.apache.activemq.broker.BrokerService : ActiveMQ JMS Message Broker (localhost, ID:CZ408016-49987-1470397291692-0:1) started 
[   main] o.a.activemq.broker.TransportConnector : Connector vm://localhost Started 
[   main] o.s.j.e.a.AnnotationMBeanExporter  : Registering beans for JMX exposure on startup 
[   main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647 
[   main] c.c.e.asynqueue.spring.Application  : Started Application in 3.117 seconds (JVM running for 4.52) 

但是我假定,然后我可以连接到经纪商白衣下面的代码:

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); 
// Create a Connection 
Connection connection = connectionFactory.createConnection(); 
connection.start(); 
相关问题