Hi,

There are some issues with camel jmx beans registration when context start 
vetoed couple of times. Camel doesn't unregister mbeans after second veto due 
to context status is stopped (assuming everything is stopped). But registration 
and un-registration happens in DefaultManagementLifecycleStrategy in onStart or 
onStop accourdinally. And onStop is not called due to mentioned above. As 
result we have couple of registered mbeans which is because they are pointed to 
the same CamelContext. We haven't observed the same in camel 2.17.7. It 
appeared after migration to the 2.25.4.

Example to reproduce:

import org.apache.camel.CamelContext;
import org.apache.camel.VetoCamelContextStartException;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.LifecycleStrategySupport;
import org.junit.Test;

public class CamelLifecycleTest {
    @Test
    public void test() throws Exception {
        CamelContext camelContext = new DefaultCamelContext();
        camelContext.addLifecycleStrategy(new ClusterFormedLifecycleStrategy());

        //to emulate start up
        camelContext.start();
        camelContext.start();
        camelContext.start();
    }

}

class ClusterFormedLifecycleStrategy extends LifecycleStrategySupport {
    private int count = 1;

    @Override
    public void onContextStart(CamelContext context) throws 
VetoCamelContextStartException {

        if (count < 3) {
            count++;
            throw new VetoCamelContextStartException("Not formed", context, 
false);
        }
    }
}

Warnings which we also have:
2022-03-25 16:33:00,946 | WARN | pool-1-thread-9 | 
amel.management.DefaultManagementLifecycleStrategy 187 | This 
CamelContext(Context1) will be registered using the name: Context1-1 due to 
clash with an existing name already registered in MBeanServer.
2022-03-25 16:33:00,951 | WARN | pool-1-thread-8 | 
amel.management.DefaultManagementLifecycleStrategy 187 | This 
CamelContext(Contex2) will be registered using the name: Contex2-2 due to clash 
with an existing name already registered in MBeanServer.

We have asked the same on stackoverflow. 
https://stackoverflow.com/questions/71609626/duplication-of-camel-context-mbeans-after-vetoed-start





Reply via email to