Amol Mandloi
Amol Mandloi

Reputation: 1

ActiveMQ Classic is showing slave even though it is a master

I am very new to ActiveMQ Classic 5.16.3. I got couple of servers installed using master-slave architecture. When I am trying to run curl <ip_addreess>:<port_no> from the server where ActiveMQ server is installed, I am getting slave as an output instead of master. But when I hit the url in the UI, I am able to view the ActiveMQ web console on screen. (I assume that the server where ActiveMQ is master will only display the page and not the actual slave).

enter image description here

Although the output of curl command in slave is coming as slave only. I am not getting what is wrong with the setup.

Please find output of curl command:

enter image description here

Upvotes: 0

Views: 48

Answers (1)

Paul
Paul

Reputation: 1170

so, I'm new to ActiveMQ as well. Been struggling to patch together all the documentation into a working Java21 SpringBoot3.x.x application for a broker-cluster distributed over 3 servers.

Not sure whether your version complies, but this is in-program possible by utilizing Jolokia and Rest Api with ActiveMQ v6.1.5. May it serve others.

For minimalistic POC, comment out the cors-config within the broker itself underneath path /conf/jolokia-access.xml. Please configure proper origins instead!

import org.springframework.web.client.RestTemplate;    

private boolean isBrokerMaster(@Nonnull String host) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.setBasicAuth(jolokiaUser, jolokiaPassword);

        boolean calledBrokerIsSlave = restTemplate.postForEntity(
                String.format("http://%s:8161/api/jolokia/", host),
                new HttpEntity<>("""
                        {
                        "type":"read",
                        "mbean":"org.apache.activemq:type=Broker,brokerName=yourBrokerName",
                        "attribute":"Slave"
                        }
                        """, headers),
                JolokiaResponse.class
        ).getBody().getValue();

        return !calledBrokerIsSlave;
    }

I wrote my own parse-classes for more versitale in-program handling, these use Lombok annotations.

@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class JolokiaResponse {

    private JolokiaRequestBody request;
    private Boolean value;
    private Long status;
}

Please note that I changed the object-type of variable value to serve this example and simplify the code. Since the return-type may differ depending on the attribute used in the POST-call, I personally changed this field to type Object.

@Getter
@Setter
@ToString
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class JolokiaRequestBody {

    // Jolokia accepts every variable case-sensitive
    private String type;
    private String mbean;
    private String attribute;
    private String path = "";
}

Do yourself a pleasure and configure your prettyPrinter by placing the following within your application.properties: spring.jackson.serialization.INDENT_OUTPUT=true when you decide against using my classes and want to fiddle around with the raw HttpServletResponse

Upvotes: 0

Related Questions