public BlockingConnection blockingConnection() { return new BlockingConnection(futureConnection()); }
public FutureConnection connect() throws Exception { this.connection = mqtt.futureConnection(); Future<Void> connect = connection.connect(); return connection; }
public BlockingConnection blockingConnection() { return new BlockingConnection(futureConnection()); }
private FutureConnection createConnection(String host,String clientId) { try { MQTT client = new MQTT(); client.setHost(host); client.setClientId(clientId); return client.futureConnection(); } catch (URISyntaxException e) { getLogger().error(e.getMessage()); return null; } } private FutureConnection createConnection(String host,String clientId,String user, String password) {
/** * Get a {@link FutureConnection} to the MQTT broker. * * @return * @throws SiteWhereException */ public FutureConnection getConnection() throws SiteWhereException { FutureConnection connection = mqtt.futureConnection(); try { Future<Void> future = connection.connect(); future.await(DEFAULT_CONNECT_TIMEOUT_SECS, TimeUnit.SECONDS); return connection; } catch (Exception e) { throw new SiteWhereException("Unable to connect to MQTT broker.", e); } }
/** * Get a {@link FutureConnection} to the MQTT broker. * * @return * @throws SiteWhereException */ public FutureConnection getConnection() throws SiteWhereException { FutureConnection connection = mqtt.futureConnection(); try { Future<Void> future = connection.connect(); future.await(DEFAULT_CONNECT_TIMEOUT_SECS, TimeUnit.SECONDS); return connection; } catch (Exception e) { throw new SiteWhereException("Unable to connect to MQTT broker.", e); } }
private FutureConnection createConnection(String host,String clientId,String user, String password) { try { MQTT client = new MQTT(); client.setHost(host); client.setUserName(user); client.setPassword(password); client.setClientId(clientId); return client.futureConnection(); } catch (URISyntaxException e) { getLogger().error(e.getMessage()); return null; } }
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { if ((topic == null) && ((multicaster == null) && (routeBuilder == null))) { throw new SiteWhereException("No topic specified and no multicaster or route builder configured."); } // Required for filters. super.start(monitor); // Start multicaster if configured. if (multicaster != null) { startNestedComponent(multicaster, monitor, true); } // Start route builder if configured. if (routeBuilder != null) { startNestedComponent(routeBuilder, monitor, true); } // Use common MQTT configuration setup. this.queue = Dispatch.createQueue(getComponentId()); this.mqtt = MqttLifecycleComponent.configure(this, queue); LOGGER.info("Connecting to MQTT broker at '" + getHostname() + ":" + getPort() + "'..."); connection = mqtt.futureConnection(); try { Future<Void> future = connection.connect(); future.await(MqttLifecycleComponent.DEFAULT_CONNECT_TIMEOUT_SECS, TimeUnit.SECONDS); } catch (Exception e) { throw new SiteWhereException("Unable to connect to MQTT broker.", e); } LOGGER.info("Connected to MQTT broker."); }
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { if ((topic == null) && ((multicaster == null) && (routeBuilder == null))) { throw new SiteWhereException("No topic specified and no multicaster or route builder configured."); } // Required for filters. super.start(monitor); // Start multicaster if configured. if (multicaster != null) { startNestedComponent(multicaster, monitor, true); } // Start route builder if configured. if (routeBuilder != null) { startNestedComponent(routeBuilder, monitor, true); } // Use common MQTT configuration setup. this.queue = Dispatch.createQueue(getComponentId().toString()); this.mqtt = MqttLifecycleComponent.configure(this, queue); getLogger().info("Connecting to MQTT broker at '" + getHostname() + ":" + getPort() + "'..."); connection = mqtt.futureConnection(); try { Future<Void> future = connection.connect(); future.await(MqttLifecycleComponent.DEFAULT_CONNECT_TIMEOUT_SECS, TimeUnit.SECONDS); } catch (Exception e) { throw new SiteWhereException("Unable to connect to MQTT broker.", e); } getLogger().info("Connected to MQTT broker."); }