Search in sources :

Example 6 with JoynrMqttClient

use of io.joynr.messaging.mqtt.JoynrMqttClient in project joynr by bmwcarit.

the class MqttPahoClientTest method createMqttClientInternal.

private JoynrMqttClient createMqttClientInternal(final MqttStatusReceiver mqttStatusReceiver) {
    injector = Guice.createInjector(override(new MqttPahoModule()).with(new AbstractModule() {

        @Override
        protected void configure() {
            if (mqttStatusReceiver != null) {
                bind(MqttStatusReceiver.class).toInstance(mqttStatusReceiver);
            }
        }
    }), new JoynrPropertiesModule(properties), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MessageRouter.class).toInstance(mockMessageRouter);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(MessageRouter.SCHEDULEDTHREADPOOL)).toInstance(Executors.newScheduledThreadPool(10));
            bind(RawMessagingPreprocessor.class).to(NoOpRawMessagingPreprocessor.class);
            Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
        }
    });
    // create a new Factory because the factory caches its client.
    mqttClientFactory = injector.getInstance(MqttClientFactory.class);
    JoynrMqttClient client = mqttClientFactory.create();
    client.setMessageListener(mockReceiver);
    return client;
}
Also used : JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) MessageRouter(io.joynr.messaging.routing.MessageRouter) MqttClientFactory(io.joynr.messaging.mqtt.MqttClientFactory) JoynrMqttClient(io.joynr.messaging.mqtt.JoynrMqttClient) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) NoOpRawMessagingPreprocessor(io.joynr.messaging.NoOpRawMessagingPreprocessor) RawMessagingPreprocessor(io.joynr.messaging.RawMessagingPreprocessor) AbstractModule(com.google.inject.AbstractModule)

Example 7 with JoynrMqttClient

use of io.joynr.messaging.mqtt.JoynrMqttClient in project joynr by bmwcarit.

the class MqttPahoClientFactory method createInternal.

private JoynrMqttClient createInternal() {
    MqttPahoClient pahoClient = null;
    try {
        logger.debug("Create Mqtt Client. Address: {}", ownAddress);
        String clientId = clientIdProvider.getClientId();
        MqttClient mqttClient = new MqttClient(ownAddress.getBrokerUri(), clientId, new MemoryPersistence(), scheduledExecutorService);
        logger.info("Creating MQTT Paho client using MQTT client ID: {}", clientId);
        pahoClient = new MqttPahoClient(mqttClient, reconnectSleepMs, keepAliveTimerSec, connectionTimeoutSec, timeToWaitMs, maxMsgsInflight, maxMsgSizeBytes, cleanSession, keyStorePath, trustStorePath, keyStorePWD, trustStorePWD, mqttStatusReceiver);
    } catch (MqttException e) {
        logger.error("Create MqttClient failed", e);
    }
    return pahoClient;
}
Also used : JoynrMqttClient(io.joynr.messaging.mqtt.JoynrMqttClient) MqttClient(org.eclipse.paho.client.mqttv3.MqttClient) MemoryPersistence(org.eclipse.paho.client.mqttv3.persist.MemoryPersistence) MqttException(org.eclipse.paho.client.mqttv3.MqttException)

Aggregations

JoynrMqttClient (io.joynr.messaging.mqtt.JoynrMqttClient)7 Test (org.junit.Test)4 MqttStatusReceiver (io.joynr.messaging.mqtt.statusmetrics.MqttStatusReceiver)3 AbstractModule (com.google.inject.AbstractModule)2 JoynrPropertiesModule (io.joynr.common.JoynrPropertiesModule)2 JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)2 NoOpRawMessagingPreprocessor (io.joynr.messaging.NoOpRawMessagingPreprocessor)2 RawMessagingPreprocessor (io.joynr.messaging.RawMessagingPreprocessor)2 MessageRouter (io.joynr.messaging.routing.MessageRouter)2 MqttClient (org.eclipse.paho.client.mqttv3.MqttClient)2 MqttException (org.eclipse.paho.client.mqttv3.MqttException)2 MemoryPersistence (org.eclipse.paho.client.mqttv3.persist.MemoryPersistence)2 MqttClientFactory (io.joynr.messaging.mqtt.MqttClientFactory)1 MqttClientIdProvider (io.joynr.messaging.mqtt.MqttClientIdProvider)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 Semaphore (java.util.concurrent.Semaphore)1 MqttAddress (joynr.system.RoutingTypes.MqttAddress)1 Ignore (org.junit.Ignore)1