ActiveMQ and embedded broker

后端 未结 2 2099
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-04 12:35

EDIT: Rephrased the question:

I want to use ActiveMQ as a messenger service between my server and client applications.

I am trying to set up an embedded broker

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 13:08

    When I run your code, I got the below exception:

    javax.jms.JMSException: Could not connect to broker URL: tcp://localhost. 
    Reason java.lang.IllegalArgumentException: port out of range:-1
    

    Your broker is running and listening to port 61616, so any client which tries to connect to broker need to have the port in its URL.

    The client code tries to connect to localhost but doesn't mention the port to which it has to connect. Both the producer and consumer code needs to be fixed.

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost");
    

    To

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    

    After fixing the port, I was able to run your code.

提交回复
热议问题