Auf Thema antworten

Hi ich habe einen ActiveMq Broker in meinen Glassfishserver deployed. Ich möchte nun, dass der Broker über Mqtt kommuniziert. Ich habe einen paho mqtt client den ich nutzen will. Im Ressource Adapter für ActiveMq habe ich folgende Einstellungen:

ServerUrl:vm://0.0.0.0:61616

BrokerXMLConfig:broker:(tcp://0.0.0.0:1883)


In der broker-config xml steht:

[code]    <transportConnectors>

      <transportConnector name="openwire" uri="tcp://localhost:61616"/>

     <transportConnector name="mqtt" uri="mqtt+nio://0.0.0.0:1883"/>

    </transportConnectors>[/code]


und in der ra.xml habe ich:

[code]        <config-property>

            <description>

              The URL to the ActiveMQ server that you want this connection to connect to.  If using

              an embedded broker, this value should be 'vm://localhost'.

            </description>

            <config-property-name>ServerUrl</config-property-name>

            <config-property-type>java.lang.String</config-property-type>

            <!--<config-property-value>tcp://localhost:61616</config-property-value>-->

            <config-property-value>vm://localhost</config-property-value>

        </config-property>


       <config-property>

            <description>

              Sets the XML configuration file used to configure the embedded ActiveMQ broker via

              Spring if using embedded mode.

           

              BrokerXmlConfig is the filename which is assumed to be on the classpath unless

              a URL is specified. So a value of foo/bar.xml would be assumed to be on the

              classpath whereas file:dir/file.xml would use the file system.

              Any valid URL string is supported.            

            </description>

            <config-property-name>BrokerXmlConfig</config-property-name>

            <config-property-type>java.lang.String</config-property-type>

            <config-property-value></config-property-value>

            <!--

             To use the broker-config.xml from the root for the RAR-->

               <!--<config-property-value>xbean:broker-config.xml</config-property-value>-->

             <!--To use an external file or url location

               <config-property-value>xbean:file:///amq/config/jee/broker-config.xml</config-property-value>

            -->

        </config-property>[/code]

Bei der configproperty BrokerXmlConfig würde ich eigentlich auf <config-property-value>xbean:broker-config.xml</config-property-value> stellen, aber danach funktioniert der Broker nicht mehr richtig. Kann mir jemand bei den Einstellungen helfen? Ich will mqtt über den Port 1883 erreichen.

Der Testcode für den Client ist:

[code]    public static void main(String[] args) {

        String topic = "MQTT Examples";

        String content = "Message from MqttPublishSample";

        int qos = 2;

        String broker = "tcp://localhost:1883";

        String clientId = "JavaSample";

        MemoryPersistence persistence = new MemoryPersistence();

      

        try


        {

            MqttClient sampleClient = new MqttClient(broker, clientId, persistence);

            sampleClient.setTimeToWait(5000);

            MqttConnectOptions connOpts = new MqttConnectOptions();

            connOpts.setCleanSession(true);

            System.out.println("Connecting to broker: " + broker);

            sampleClient.connect(connOpts);

            System.out.println("Connected");

            System.out.println("Publishing message: " + content);

            MqttMessage message = new MqttMessage(content.getBytes());

            message.setQos(qos);

            sampleClient.publish(topic, message);

            System.out.println("Message published");

            sampleClient.disconnect();

            System.out.println("Disconnected");

            System.exit(0);

        } catch (


        MqttException me)


        {

            System.out.println("reason " + me.getReasonCode());

            System.out.println("msg " + me.getMessage());

            System.out.println("loc " + me.getLocalizedMessage());

            System.out.println("cause " + me.getCause());

            System.out.println("excep " + me);

            me.printStackTrace();

        }

    }[/code]

Danke für die Hilfe im vorraus



Oben