Home > Blockchain >  Connection to localhost failed - ActiveMQ in MacOs
Connection to localhost failed - ActiveMQ in MacOs

Time:03-30

I started a project in java with ActiveMQ 5.17.0. Therefore I have downloaded ActiveMQ and opened my terminal from the folder bin and execute ./activemq start.

I received:

INFO: Loading '/Users/NAME/Downloads/apache-activemq-5.17.0//bin/env'
INFO: Using java '/usr/bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
./activemq: line 343: [: : integer expression expected
INFO: pidfile created : '/Users/NAME/Downloads/apache-activemq-5.17.0//data/activemq.pid' (pid '3084')

As I have seen in other posts, this is the expected result.

A part of my Java Code is:

public static void main(String[] args) {
    ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:8161"); // ActiveMQ-specific
    Connection con = null;
    try {
        con = factory.createConnection();
        Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); // non-transacted session

        Queue queue = session.createQueue("test.queue"); // only specifies queue name

        MessageProducer producer = session.createProducer(queue);
        Message msg = session.createTextMessage("hello queue"); // text message
        producer.send(msg);

    } catch (JMSException e) {
        e.printStackTrace();
    } finally {
        if (con != null) {
            try {
                con.close(); // free all resources
            } catch (JMSException e) { /* Ignore */ }
        }
    }
}

As soon as I try to open the website https://localhost:8161/admin/admin I receive the response that Safari, Chrome, and Firefox do not get connection to localhost.

Anybody any suggestions what to do?

I have already tried to download again, different browsers, start and stop the server several times.

CodePudding user response:

  1. The URL for the admin UI should be http: http://localhost:8161/admin or http://127.0.0.1:8161/admin/

  2. The script activemq fails parsing the output of java -version. Maybe set the line VERSION= to your java version (e.g. VERSION=17 for java 17) to check if that is the issue.

CodePudding user response:

Your code sample shows that you are attempting to send messages to the Web UI URL vs the JMS protocol port.

Try changing your code to use port '61616':

        ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616); // ActiveMQ-specific

For the web browser access, try starting with the non-SSL url: http://localhost:8161/admin/admin instead of 'https'.

  • Related