Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UH OH!! MqttException (0) : Message not send after user update #4

Closed
ghost opened this issue Apr 28, 2021 · 2 comments
Closed

UH OH!! MqttException (0) : Message not send after user update #4

ghost opened this issue Apr 28, 2021 · 2 comments

Comments

@ghost
Copy link

ghost commented Apr 28, 2021

Hi,

when i update a user in keycloak, i get this error.
The mqtt broker does not received the message.

15:39:20,487 INFO [stdout] (default task-2) UH OH!! MqttException (0)
15:39:20,488 ERROR [stderr] (default task-2) MqttException (0)
15:39:20,489 ERROR [stderr] (default task-2) at deployment.event-listener-mqtt-9.0.0-jar-with-dependencies.jar//org.eclipse.paho.client.mqttv3.persist.MqttDefaultFilePersistence.open(MqttDefaultFilePersistence.java:85)

Here is the associated code of the error :

https://github.com/eclipse/paho.mqtt.java/blob/master/org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/persist/MqttDefaultFilePersistence.java

public void open(String clientId, String theConnection) throws MqttPersistenceException {
		
		if (dataDir.exists() && !dataDir.isDirectory()) {
			throw new MqttPersistenceException();
		} else if (!dataDir.exists() ) {
			if (!dataDir.mkdirs()) {
				throw new MqttPersistenceException();
			}
		} 
		if (!dataDir.canWrite()) {
			throw new MqttPersistenceException();
		}
...
}

Here is my docker-compose

version: '3'
services:
  mqtt:
      image: "hivemq/hivemq4"
      container_name: "mqtt"
      ports:
        - 1883:1883
        - 8883:8883
      networks:
        - my-project
  keycloak:
    build:
      context: ./keycloak
      dockerfile: Dockerfile
    container_name: "keycloak"
    environment:
      DB_VENDOR: mysql
      DB_ADDR: mysql
      DB_PORT: 3306
      DB_DATABASE: myproject
      DB_USER: myproject
      DB_PASSWORD: myproject
      KEYCLOAK_USER: admin
      KEYCLOAK_PASSWORD: admin
      KEYCLOAK_IMPORT: /opt/jboss/keycloak/imports/keycloak-myproject.json -Dkeycloak.profile.feature.upload_scripts=enabled          
      PROXY_ADDRESS_FORWARDING: "true"
      KEYCLOAK_LOGLEVEL: ALL
      MQTT_HOST: tcp://mqtt:1883
    command: ["-c=standalone.xml"]
    volumes:
      - ./keycloak/imports:/opt/jboss/keycloak/imports
    ports:
      - '8092:8080'
      - '8443:8443'
      - '9990:9990'
    depends_on:
      - mysql
      - mqtt
    links:
      - mysql
      - mqtt
    networks:
      - my-project

Le standalone.xml

<spi name="eventsListener">
                <provider name="mqtt" enabled="true">
                    <properties>
                        <property name="serverUri" value="tcp://127.0.0.1:1883"/>
                        <property name="username" value=""/>
                        <property name="password" value=""/>
                        <property name="topic" value="keycloak"/>
                    </properties>
                </provider>
            </spi>

my Dockerfile

FROM jboss/keycloak:11.0.2
COPY event-listener-mqtt-9.0.0-jar-with-dependencies.jar /opt/jboss/keycloak/standalone/deployments/event-listener-mqtt-9.0.0-jar-with-dependencies.jar
COPY startup-config.cli /opt/jboss/startup-scripts/startup-config.cli
COPY ./imports/keycloak-realm.json /opt/jboss/keycloak/keycloak-realm.json

and my startup-config.cli

embed-server --std-out=echo
/subsystem=keycloak-server/spi=eventsListener/:add
/subsystem=keycloak-server/spi=eventsListener/provider=mqtt/:add(properties={"serverUri" => "tcp://localhost:1883", "topic" => "keycloak"}, enabled=true)
stop-embedded-server

In keycloak, the mqtt logger is selected.
The mqtt run well. I MQTTBox to send message on it.

How can i resolve this error ?

Thanks a lot

@mhuin
Copy link
Collaborator

mhuin commented Apr 29, 2021

Hello,
I think this might be related to #2
It looks like this extension doesn't work well with the keycloak docker image due to some differences with file permissions.
PR #3 might fix your problem. If you could test it and confirm, I'll commit it myself.

@mhuin
Copy link
Collaborator

mhuin commented Sep 12, 2022

Hello,

Apologies for the late followup. I believe the problem is fixed in the latest release - at least it is possible to disable persistence altogether in the settings.

If the problem persists, please reopen an issue.

@mhuin mhuin closed this as completed Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant