Disable JMX/MBeans in JVM

1.4k Views Asked by At

I have two Debezium SQL Server connectors that have to connect to one database and publish two different tables. Their name and database.history.kafka.topic are unique. Still when adding the second one (using a POST request) I get below exceptions. I don't want to use a unique value for database.server.name which counterintuitively has been used for metric name.

java.lang.RuntimeException: Unable to register the MBean 'debezium.sql_server:type=connector-metrics,context=schema-history,server=mydatabase'
Caused by: javax.management.InstanceAlreadyExistsException: debezium.sql_server:type=connector-metrics,context=schema-history,server=mydatabase

We won't be using JMX/MBeans so it's okay to disable it, but the question is how. If there is a common way to do it for JVM please advise.

I even see below code in Debezium where it registers a MBean. Looking just at two first lines, it seems one way to bypass this issue is forcing ManagementFactory.getPlatformMBeanServer() to return null. So another way of asking the same question may be how to force ManagementFactory.getPlatformMBeanServer() return null?

public synchronized void register() {
    try {
        final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        if (mBeanServer == null) {
            LOGGER.info("JMX not supported, bean '{}' not registered", name);
            return;
        }
        // During connector restarts it is possible that Kafka Connect does not manage
        // the lifecycle perfectly. In that case it is possible the old metric MBean is still present.
        // There will be multiple attempts executed to register new MBean.
        for (int attempt = 1; attempt <= REGISTRATION_RETRIES; attempt++) {
            try {
                mBeanServer.registerMBean(this, name);
                break;
            }
            catch (InstanceAlreadyExistsException e) {
                if (attempt < REGISTRATION_RETRIES) {
                    LOGGER.warn(
                            "Unable to register metrics as an old set with the same name exists, retrying in {} (attempt {} out of {})",
                            REGISTRATION_RETRY_DELAY, attempt, REGISTRATION_RETRIES);
                    final Metronome metronome = Metronome.sleeper(REGISTRATION_RETRY_DELAY, Clock.system());
                    metronome.pause();
                }
                else {
                    LOGGER.error("Failed to register metrics MBean, metrics will not be available");
                }
            }
        }
        // If the old metrics MBean is present then the connector will try to unregister it
        // upon shutdown.
        registered = true;
    }
    catch (JMException | InterruptedException e) {
        throw new RuntimeException("Unable to register the MBean '" + name + "'", e);
    }
}
1

There are 1 best solutions below

2
Dude0001 On

You should use a single Debezium SQL Server connector for this, and use the table.include.list property on the connector to list the two tables you want to capture.

https://debezium.io/documentation/reference/stable/connectors/sqlserver.html#sqlserver-property-table-include-list