OH3 starting 2 MQTT Brokers

Hi,
I’m having some trouble configuring my MQTT.
At the start of Openhab it looks like it’s trying to start 2 MQTT brokers and then crashes, the broker stays offline.:

2021-01-11 22:18:58.750 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid c812c8f1-9b03-4508-bb75-13a2cc7be56b

2021-01-11 22:18:59.071 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to '192.168.178.50' with clientid b8c56f84-d217-40a4-a0e8-841ce6cdcda7

2021-01-11 22:18:59.188 [ERROR] [org.openhab.binding.mqtt            ] - bundle org.openhab.binding.mqtt:3.0.0 (227)[org.openhab.binding.mqtt.internal.discovery.MqttServiceDiscoveryService(282)] : The activate method has thrown an exception

Unfortunately in the UI I can only see one broker, the one with the IP Address.
How can I kill the other broker without seeing it?
What I already found out:
When I start the mosquitto service with:
mosquitto -d
over ssh and save the broker again, it comes online, everything works, I just get the message;

2021-01-11 22:33:09.543 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to 'localhost'. Next attempt in 60000ms

2021-01-11 22:33:09.547 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid c812c8f1-9b03-4508-bb75-13a2cc7be56b

every minute in the log.
Your help is appreciated.
Thanks and best regards
Daniel

Those are about openHAB connecting to a broker, nothing to do with the actual broker service(s) (e.g. mosquitto) which won’t be putting anything in your openHAB logs.

Okay, so openHAB is attempting to connect to two brokers (that’s allowed) and it suggests that you have two MQTT Bridge broker Things configured. But you don’t want two Bridges by different paths to one real broker.
Maybe one by file, one by UI?

Hi rossko,
thanks for your answer. I have some things defined over files, but not the broker. I also tried to delete all thing files and restarted, but had 2 brokers trying to start anyway. Anyway shouldn’t I see both brokers in the UI then one with a lock one without?
I also just tried to clear the cache. But still have 2 mqtt brokers starting.
I also get this error now when the 2 brokers are trying to start:

2021-01-12 10:37:25.015 [ERROR] [org.openhab.binding.mqtt            ] - bundle org.openhab.binding.mqtt:3.0.0 (241)[org.openhab.binding.mqtt.internal.discovery.MqttServiceDiscoveryService(275)] : The activate method has thrown an exception

java.lang.IllegalArgumentException: ID segment 'localhost:s' contains invalid characters. Each segment of the ID must match the pattern [\w-]*.

	at org.openhab.core.common.AbstractUID.validateSegment(AbstractUID.java:98) ~[?:?]

	at org.openhab.core.common.AbstractUID.<init>(AbstractUID.java:76) ~[?:?]

	at org.openhab.core.common.AbstractUID.<init>(AbstractUID.java:59) ~[?:?]

	at org.openhab.core.thing.UID.<init>(UID.java:57) ~[?:?]

	at org.openhab.core.thing.ThingUID.<init>(ThingUID.java:47) ~[?:?]

	at org.openhab.binding.mqtt.internal.discovery.MqttServiceDiscoveryService.brokerAdded(MqttServiceDiscoveryService.java:105) ~[?:?]

	at org.openhab.binding.mqtt.internal.discovery.MqttServiceDiscoveryService.lambda$1(MqttServiceDiscoveryService.java:85) ~[?:?]

	at java.util.concurrent.ConcurrentHashMap.forEach(ConcurrentHashMap.java:1603) ~[?:?]

	at java.util.Collections$UnmodifiableMap.forEach(Collections.java:1505) ~[?:?]

	at org.openhab.binding.mqtt.internal.discovery.MqttServiceDiscoveryService.startBackgroundDiscovery(MqttServiceDiscoveryService.java:85) ~[?:?]

	at org.openhab.core.config.discovery.AbstractDiscoveryService.activate(AbstractDiscoveryService.java:371) ~[?:?]

	at org.openhab.binding.mqtt.internal.discovery.MqttServiceDiscoveryService.activate(MqttServiceDiscoveryService.java:54) ~[?:?]

	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]

	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]

	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]

	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]

	at org.apache.felix.scr.impl.inject.methods.BaseMethod.invokeMethod(BaseMethod.java:228) ~[bundleFile:?]

	at org.apache.felix.scr.impl.inject.methods.BaseMethod.access$500(BaseMethod.java:41) ~[bundleFile:?]

	at org.apache.felix.scr.impl.inject.methods.BaseMethod$Resolved.invoke(BaseMethod.java:664) ~[bundleFile:?]

	at org.apache.felix.scr.impl.inject.methods.BaseMethod.invoke(BaseMethod.java:510) [bundleFile:?]

	at org.apache.felix.scr.impl.inject.methods.ActivateMethod.invoke(ActivateMethod.java:317) [bundleFile:?]

	at org.apache.felix.scr.impl.inject.methods.ActivateMethod.invoke(ActivateMethod.java:307) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:340) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:114) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:982) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:955) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:900) [bundleFile:?]

	at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse$1.run(ServiceFactoryUse.java:212) [org.eclipse.osgi-3.12.100.jar:?]

	at java.security.AccessController.doPrivileged(Native Method) [?:?]

	at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.factoryGetService(ServiceFactoryUse.java:210) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.serviceregistry.ServiceFactoryUse.getService(ServiceFactoryUse.java:111) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.serviceregistry.ServiceConsumer$2.getService(ServiceConsumer.java:45) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:508) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.getService(ServiceRegistry.java:461) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.BundleContextImpl.getService(BundleContextImpl.java:624) [org.eclipse.osgi-3.12.100.jar:?]

	at org.apache.felix.scr.impl.manager.SingleRefPair.getServiceObject(SingleRefPair.java:86) [bundleFile:?]

	at org.apache.felix.scr.impl.inject.BindParameters.getServiceObject(BindParameters.java:47) [bundleFile:?]

	at org.apache.felix.scr.impl.inject.methods.BindMethod.getServiceObject(BindMethod.java:664) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.DependencyManager.getServiceObject(DependencyManager.java:2308) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.DependencyManager.doInvokeBindMethod(DependencyManager.java:1805) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.DependencyManager.invokeBindMethod(DependencyManager.java:1788) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.SingleComponentManager.invokeBindMethod(SingleComponentManager.java:435) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.DependencyManager$MultipleDynamicCustomizer.addedService(DependencyManager.java:325) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.DependencyManager$MultipleDynamicCustomizer.addedService(DependencyManager.java:294) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1216) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.customizerAdded(ServiceTracker.java:1137) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.trackAdding(ServiceTracker.java:944) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.ServiceTracker$AbstractTracked.track(ServiceTracker.java:880) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:1168) [bundleFile:?]

	at org.apache.felix.scr.impl.BundleComponentActivator$ListenerInfo.serviceChanged(BundleComponentActivator.java:125) [bundleFile:?]

	at org.eclipse.osgi.internal.serviceregistry.FilteredServiceListener.serviceChanged(FilteredServiceListener.java:109) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:920) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEventPrivileged(ServiceRegistry.java:862) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.publishServiceEvent(ServiceRegistry.java:801) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistrationImpl.register(ServiceRegistrationImpl.java:127) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.serviceregistry.ServiceRegistry.registerService(ServiceRegistry.java:225) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.BundleContextImpl.registerService(BundleContextImpl.java:469) [org.eclipse.osgi-3.12.100.jar:?]

	at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:906) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:892) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:128) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:959) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:732) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:666) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:432) [bundleFile:?]

	at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:665) [bundleFile:?]

	at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:338) [bundleFile:?]

	at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:382) [bundleFile:?]

	at org.apache.felix.scr.impl.Activator.access$200(Activator.java:49) [bundleFile:?]

	at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:264) [bundleFile:?]

	at org.apache.felix.scr.impl.AbstractExtender.createExtension(AbstractExtender.java:196) [bundleFile:?]

	at org.apache.felix.scr.impl.AbstractExtender.modifiedBundle(AbstractExtender.java:169) [bundleFile:?]

	at org.apache.felix.scr.impl.AbstractExtender.modifiedBundle(AbstractExtender.java:49) [bundleFile:?]

	at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:482) [osgi.core-6.0.0.jar:?]

	at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:415) [osgi.core-6.0.0.jar:?]

	at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232) [osgi.core-6.0.0.jar:?]

	at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444) [osgi.core-6.0.0.jar:?]

	at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:908) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:213) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:120) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:112) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:168) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.container.Module.publishEvent(Module.java:476) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.container.Module.start(Module.java:467) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) [org.eclipse.osgi-3.12.100.jar:?]

	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:402) [org.eclipse.osgi-3.12.100.jar:?]

	at org.apache.karaf.features.internal.service.BundleInstallSupportImpl.startBundle(BundleInstallSupportImpl.java:165) [bundleFile:?]

	at org.apache.karaf.features.internal.service.FeaturesServiceImpl.startBundle(FeaturesServiceImpl.java:1153) [bundleFile:?]

	at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:1036) [bundleFile:?]

	at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1062) [bundleFile:?]

	at org.apache.karaf.features.internal.service.FeaturesServiceImpl.lambda$doProvisionInThread$13(FeaturesServiceImpl.java:998) [bundleFile:?]

	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]

	at java.lang.Thread.run(Thread.java:834) [?:?]

Cleaning cache was pretty much the last idea I had.

Best regards
Daniel

Hello Daniel.

were you able to solve this problem?
I have the same here:

2021-02-12 16:32:48.119 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid 6f452704-e54d-438d-80ea-aecee73ff5e1

2021-02-12 16:32:48.245 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'localhost' with clientid 849239c8-9334-4777-a127-b05bf8ae8f38

This thread goes into more detail.

Essentially, OH3 gives some people a “System broker” type Thing whether they want it or not. You don’t want it in OH3 at all, just your regular bridge broker Thing, but this “system broker” seems hard to get rid of.

Hi Cidi,
I actually did :slight_smile: I had a broker normally set up over Settings -> Things. Additionally I made entries in Settings -> MQTT System broker connection because I thought that needs to be done additionally. But that created a new “hidden” system broker. Taking away these settings solved it.
Hope that helps.
Best regards
Daniel

1 Like

Hello Daniel.
Thanks for the info.
I have removed all entries from the SystemBroker (in Settings -> MQTT system broker connection) and saved. Since then the message comes for one of the two brokers: Try to restore connection to ‘localhost’.
It seems to be related but it does not delete the SystemBroker.
With both it runs now. Maybe I better leave it like this.

@cidi is your setup an upgrade from OH2, or a complete fresh start? And did you initially enter values into the System Broker settings yourself, like @HDaniel did?

In a nutshell:
It is a fresh installation on Raspi 4.
installed the Mosquitto via openhabian-config. Added the binding and then entered name and password in the “Settings - MQTT system broker connection”.
Then via Things - Manual plus - MQTT Binding: added a MQTT Broker (not SystemBroker) and entered host (localhost). Channels and Items created and connected.
My test Sonoff works fine now. I only think that I have one broker too many.

When I take out my manual settings (actually only name and password for the Mosquitto) from the Settings-MQTT system broker connection and save it, I get the error message that it can not connect. Not even after reboot. Otherwise no entries were made there.

Can you login over ssh and try
“mosquitto -d”
Somehow my mqtt service also refuses to start automatically. When I do mosquitto -d and save the broker everything works again.

I removed my entries from the System Broker and entered

mosquitto -d

on the console.
After the reboot now only 1 broker starts (the right one) and for the second one I get the message:
[WARN ] [.MqttBrokerConnectionServiceInstance] - Ignore invalid broker connection configuration
I think so I leave it for now.
thank you