How to resolve mqtt broker issue: Connection Refused: unacceptable protocol version.? - docker

I have a a group of docker containers which I start from a docker-compose file.They communicate with each other via an MQTT Broker. This all works good. I have this set of containers deployed to an Ubuntu enviornment and I want to use the MQTTX CLI tool so I can publish and subbscribe from an Ubuntu terminal.
Here is where the problem comes, I have installed MQTTX CLI at the Ubuntu and I try to subcribe and publish but connection is refused because of my protocol version of mqtt being unacceptable.
This is my broker version:
As I have said, it works fine, services are able to communicate well but I cannot subscribe or publish to the topics because of that issue which I am not sure how to resolve. I tried
adding 'bridge_protocol_version mqttv311' to the mosquitto config file but that did not help.

The MQTT X documentation clearly states that it defaults to MQTT v5
Options Description
-V, --mqtt-version <5/3.1.1/3.1> the MQTT version (default: 5)
-h, --hostname the broker host (default: "localhost")
-p, --port the broker port
-i, --client-id the client id
--no-clean set the clean session flag to false (default: true)
-k, --keepalive send a ping every SEC seconds (default: 30)
As Version 5 of the MQTT spec was not ratified until March 2019, the version of your MQTT broker is from 2017 it can't possibly support v5 (that and the help output lists the supported version 3.1.1 & 3.1).

Related

MQTT connection refused when trying to connect from remote machine

I am trying to connect to a mosquitto broker, across linux clients. I can get everything working from the local machine, but when trying to connect from another machine I get the error ConnectionRefusedError: [Error 111] Connection refused.
Here is the process:
On the local machine, I install mostquitto, stop the service and start a live instance:
#Terminal 1
sudo service mosquitto stop
mosquitto
I then try and pub and sub, from distinct terminals on that machine:
#Terminal 2
mosquitto_sub -t 'test'
#Terminal 1 shows new connection
#Terminal 3
mosquitto_pub -t 'test' -m 'Hello, world!'
#Terminal 1 shows new connection, and then disconnect.
#Terminal 2 shows 'Hello, world!'
I now try to connect from a remote machine. First I edit the mosquitto config file to allow unauthorized connections:
sudo nano /etc/mosquitto/mosquitto.conf
#Add the following:
listener 1883
allow_anonymous true
protocol mqtt
I note that the mosquitto logs previously showed only local connections allowed, after editing the config file and restarting, the logs no longer show that message.
Then I install paho-mqtt on another machine. I run the following python script:
import paho.mqtt.client as mqtt
client = mqtt.Client('131')
client.connect('192.168.0.146') #The IP of machine 1, running the broker where the code above ran correctly across the terminals
I get the error mentioned above:ConnectionRefusedError: [Error 111] Connection refused. The mosquitto instance on machine 1 shows nothing. Logs show nothing.
I can't work out what is going on. I have read every question on SO that I can find. Nothing goes beyond changing the config file. I have tried running the broker on two machines (laptop and pi). I have tried connecting from multiple different sources: esp32 board, different laptop and pi. Nothing works. I can only assume there is some network-wide problem, but my network isn't isolating devices as I ssh into my pi all the time and have wifi lights and switches running on the LAN.
If anyone can help me troubleshoot I would be very grateful.
Mosquitto will not pick up a default configuration file, you must always pass the configuration file with the -c command line argument or it will fall back to the baked in config (that will only listen on localhost)
The service includes -c /etc/mosquitto/mosquitto.conf to force it to use the config file.

Publishing or subscribing data via external IP

I am running Mosquitto MQTT broker on the localhost of my PC and I want to publish or subscribe data through MQTT with Mosquitto from a remote IP (another PC). Both the PCs are connect to the same Wifi public network. I have disable the firewall of the two PCs and I am able to ping one another on command prompt. I have look up on several websites and tried editing the config file of the Mosquitto MQTT broker by adding these two lines.
listener 1883
allow_anonymous true
I have started the Mosquitto broker by executing mosquitto -c mosquitto.conf -v
The following is the log appear the mosquitto start.
C:\Program Files\mosquitto>mosquitto -c mosquitto.conf -v
1665133477: mosquitto version 2.0.15 starting
1665133477: Config loaded from mosquitto.conf.
1665133477: Opening ipv6 listen socket on port 1883.
1665133477: Opening ipv4 listen socket on port 1883.
1665133477: mosquitto version 2.0.15 running
However, on the publishing PC, it prompts the error below.
C:\Program Files\mosquitto>mosquitto_pub -h XXX.XXX.XX.X -t Test -m "Hello World" -p 8883 -d
Error: No connection could be made because the target machine actively refused it.
The situation is same for subscribing. I am currently using the latest version of Mosquitto 2.0.15. Can anyone help me on this situation? Your help would be much appreciated. Thanks in advance!

Docker Desktop 3.3.0+ breaks SSH on port 443: how to fix?

I am using Docker Desktop for Mac.
Since version 3.3.0 and with 3.3.1 I cannot connect to altssh.gitlab.com on port 443 any more whereas 3.2.2 and earlier work.
So, these commands both work in 3.2.2 (I downgraded and verified):
$ ssh git#gitlab.com
$ ssh -p 443 git#altssh.gitlab.com
Both produce output like this:
PTY allocation request failed on channel 0
Welcome to GitLab, #user!
Connection to altssh.gitlab.com closed.
With 3.3.0 and 3.3.1 however, only ssh git#gitlab.com was working while port 443 was seemingly proxied or intercepted by Docker, resulting in this:
kex_exchange_identification: Connection closed by remote host
I verified with nc gitlab.com 22 (netcat) that gitlab.com at port 22 replied:
SSH-2.0-OpenSSH_7.9p1 Debian-10+deb10u2
nc altssh.gitlab.com 443 also prints that text in 3.2.2 but shows nothing and just hangs in 3.3.0+.
I looked at the release notes for 3.3.0 here:
https://docs.docker.com/docker-for-mac/release-notes/
Tried setting noProxy in ~/.docker/config.json because it was mentioned together with HTTPS and restarted Docker Desktop but it changed nothing:
{
"proxies": {
"default": {
"noProxy": "altssh.gitlab.com,075e5c94415c4071840fa96497443943.pacloudflare.com,172.65.251.182,2606:4700:90:0:f0ff:e6a3:2ac:f7ef"
}
}
}
Is there a way to use Docker 3.3.0+ with SSH on port 443 / altssh.gitlab.com?
As of Docker 3.3.2 and newer, the bug has been fixed.
From the 3.3.2 release notes:
• Disable the HTTP and HTTPS transparent proxies when there is no upstream proxy set. Fixes docker/for-mac#5572.
• Revert to the HTTP and HTTPS proxy implementation used in 3.2.2.
Previously...
Looks like the bug is known, though not exactly in this context.
The reason being that supposed "HTTPS" / TLS connections are dropped when they do not use SNI (server name indication), which SSH as a non-SSL/TLS protocol probably does not do.
There's already an open Docker Desktop for Mac issue:
https://github.com/docker/for-mac/issues/5568
And the linked StackOverflow question:
Cannot reach SSL IP when in docker container over bridge. Getting SSL_ERROR_SYSCALL

WildFly 10.0 port offset "9" can't connect to CLI at 9999

I need to run a WildFly 10.0.0 instance with a jboss.socket.binding.port-offset=9
It start but I'm not able to connect to CLI with port 9999 (9990+offset)
When you use port 9999, CLI will by default fallback to remoting protocol (EAP 6 default) and won't be able to connect to the EAP 7 although the correct port number is used. Because of this, you have to use protocol while connecting to remote server instance, like as:
$JBOSS_HOME/bin/jboss-cli.sh -c --controller=http-remoting://localhost:9999

Mosquitto MQTT Bridge Error

I am trying to bridge my local (Windows) MQTT mosquitto broker to test.mosquitto.org. Unfortunately it raises a Unknown Error.
I am using the same configuration that is used in this question
Verify that local mosquitto MQTT Broker is bridged to test.mosquitto.org
Config file:
connection test
address test.mosquitto.org
topic oust_topicst_topic out 0
try_private false
notifications false
bridge_attempt_unsubscribe true
Output:
1489747961: mosquitto version 1.4.11 (build date 20/02/2017 23:24:29.40) starting
1489747961: Config loaded from Configurations/bridge.conf.
1489747961: Opening ipv6 listen socket on port 1883.
1489747961: Opening ipv4 listen socket on port 1883.
1489747961: Bridge local.NicolasJourdan.test doing local SUBSCRIBE on topic oust_topicst_topic
1489747961: Connecting bridge test (test.mosquitto.org:1883)
1489747961: Bridge NicolasJourdan.test sending CONNECT
1489747961: Error creating bridge: Unknown error.
1489747961: Warning: Unable to connect to bridge test.
1489747969: mosquitto version 1.4.11 terminating
What could produce this error? I am not running another instance of mosquitto and test.mosquitto.org is up
First question is whether you are running a local broker or just connecting as a client.
If you are running a broker try to first run mosquitto with -c "path to config file" to see whether your config file has an error in it. Run in terminal (example on linux):
mosquitto -c /etc/mosquitto/mosquitto.conf
If there is an error the console will show it and you take it from there.
Next, try to format your topics like this (it is called topic remapping):
topic test out 0 local/ local/
Now you can publish to local/test from your code or terminal, and the message will be published to local/test on the remote broker, which will receive messages by suscribing to the same topic.
Update September 2019
The bug on Windows as described below has reportedly been fixed in version 1.6.5 of Mosquitto.
There appears to be a bug with Mosquitto running on Windows that prevents bridging from working.
On Windows the socket is not ready before Mosquitto attempts to connect.
See https://github.com/eclipse/mosquitto/issues/478 and https://github.com/eclipse/mosquitto/issues/580. This describes the underlying issue on Windows:
After checking the code I found that the statement in bridge.c .... makes a non blocking socket connect.
...
So the the next command ... sometimes fails, since the connection has not been established, as the previous connect is non-blocking.

Resources