This is my /etc/mosquitto/mosquitto.conf. I don't have anything in the directory /etc/mosquitto/conf.d
NB I generally use username/password for mosquitto, but just for this I changed to allow_anonymous true.
I had to sudo systemctl restart mosquitto and reload the Node-red browser page to get it connected.
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
#log_dest file /var/log/syslog # enable logging stops mosquitto starting log file permissions
include_dir /etc/mosquitto/conf.d
allow_anonymous true
And here is a simple flow to show how the mqtt-in and out nodes are set up and test it.
[{"id":"7ea899624d0e5932","type":"tab","label":"Flow 4","disabled":false,"info":"","env":[]},{"id":"74e2f2c11b1ec85d","type":"inject","z":"7ea899624d0e5932","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test","payload":"Testing","payloadType":"str","x":230,"y":120,"wires":[["a850a31137dc5273"]]},{"id":"a850a31137dc5273","type":"mqtt out","z":"7ea899624d0e5932","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"754230cc.99c44","x":450,"y":120,"wires":[]},{"id":"b7b07b01fa59328a","type":"mqtt in","z":"7ea899624d0e5932","name":"","topic":"test","qos":"2","datatype":"auto","broker":"754230cc.99c44","nl":false,"rap":true,"rh":0,"inputs":0,"x":250,"y":180,"wires":[["0518746599af4baf"]]},{"id":"0518746599af4baf","type":"debug","z":"7ea899624d0e5932","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":180,"wires":[]},{"id":"754230cc.99c44","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
Does this flow work for you?