3 Replies Latest reply on May 6, 2014 8:04 PM by goot

    MQTT client under JBoss

    Tony Leaf Newbie

      Hi everybody,
      I want to integrate an MQTT client (Paho for example) in my JBoss application. I get a broker running on a server and an android device taht send messages. Now i want to send/receive message form my java app under JBoss.
      I've tried to put Paho code in a @startup bean but i get an IllegalState.
      Now i'm reading a lot of documentation about MQTT but i can't find a way to integrate a MQTT Client in my AS.

      Thanks

        • 1. Re: MQTT client under JBoss
          Tomaz Cerar Master

          Show us the code sample where do you try to call paho code in @Startup bean.

          Also, what version of server are you using? JDK, and full stacktrace

          • 2. Re: MQTT client under JBoss
            Tony Leaf Newbie

            i'm using JBoss 7.1 and jdk1.7.0_45
            CODE:

             

            import javax.ejb.Singleton;

            import javax.ejb.Startup;

            import javax.annotation.PostConstruct;

            import org.eclipse.paho.client.mqttv3.MqttClient;

            import org.eclipse.paho.client.mqttv3.MqttConnectOptions;

            import org.eclipse.paho.client.mqttv3.MqttException;

            import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;

             

             

            @Singleton

            @Startup

            public class PahoClient {

             

             

                //Publish interval in seconds

                private final int DEFAULT_INTERVAL = 5;

                private final String DEVICE_STATUS_TOPIC = "test";

                private final String DEVICE_INTERVAL_TOPIC = "alive";

               

                private int interval = DEFAULT_INTERVAL;

               

                public PahoClient(){

              

                }

                @PostConstruct

                public void start() {

             

             

                    try {

                    System.out.println("STARTING MQTT CLIENT");

                        MqttClient client = new MqttClient("tcp://192.168.1.65", "test", new MemoryPersistence());

             

             

                        final MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();

                       

                        //testamento del client

                        mqttConnectOptions.setWill(DEVICE_STATUS_TOPIC, "offline".getBytes(), 2, true);

                       

                        //connessione

                        client.connect(mqttConnectOptions);

                        //listener per gli eventi asincroni

                        client.setCallback(new SubscribeCallback(this, DEVICE_INTERVAL_TOPIC));

             

             

                        if (client.isConnected()) {

             

             

                            client.publish(DEVICE_STATUS_TOPIC, "online".getBytes(), 2, true);

                            client.subscribe(DEVICE_INTERVAL_TOPIC, 2);

             

             

                            publishDataPeriodically(client);

                        } else {

                            System.out.println("Could not connect!");

                        }

                    } catch (MqttException e) {

                        e.printStackTrace();

                    }

                }

            15:42:08,692 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015876: Starting deployment of "NetworkManager.jar"

            15:42:08,816 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC00001: Failed to start service jboss.deployment.unit."NetworkManager.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."NetworkManager.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "NetworkManager.jar"

              at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_45]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_45]

              at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_45]

            Caused by: java.lang.RuntimeException: Error getting reflective information for class jms.PahoClient with ClassLoader ModuleClassLoader for Module "deployment.NetworkManager.jar:main" from Service Module Loader

              at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:58)

              at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:85)

              at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:70)

              at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:55)

              at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              ... 5 more

            Caused by: java.lang.NoClassDefFoundError: org/eclipse/paho/client/mqttv3/MqttException

              at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.7.0_45]

              at java.lang.Class.privateGetDeclaredFields(Unknown Source) [rt.jar:1.7.0_45]

              at java.lang.Class.getDeclaredFields(Unknown Source) [rt.jar:1.7.0_45]

              at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              ... 10 more

            Caused by: java.lang.ClassNotFoundException: org.eclipse.paho.client.mqttv3.MqttException from [Module "deployment.NetworkManager.jar:main" from Service Module Loader]

              at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]

              at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]

              at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]

              ... 15 more

             

             

            15:42:08,828 INFO  [org.jboss.as] (MSC service thread 1-8) JBAS015951: Admin console listening on http://127.0.0.1:9990

            15:42:08,828 ERROR [org.jboss.as] (MSC service thread 1-8) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 2801ms - Started 175 of 259 services (1 services failed or missing dependencies, 78 services are passive or on-demand)

            15:42:08,829 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "NetworkManager.jar" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"NetworkManager.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"NetworkManager.jar\".POST_MODULE: Failed to process phase POST_MODULE of deployment \"NetworkManager.jar\""}}

            15:42:08,832 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment NetworkManager.jar in 3ms

            15:42:08,833 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report

            JBAS014777:   Services which failed to start:      service jboss.deployment.unit."NetworkManager.jar".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."NetworkManager.jar".POST_MODULE: Failed to process phase POST_MODULE of deployment "NetworkManager.jar"

             

             

            15:42:08,834 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"NetworkManager.jar\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"NetworkManager.jar\".POST_MODULE: Failed to process phase POST_MODULE of deployment \"NetworkManager.jar\""}}}}

            • 3. Re: MQTT client under JBoss
              goot Newbie

              Did you finaly found a solution for this problem?

              I'd like to run an mqtt-client on jboss, too and I couldn't manage it, yet.