public byte[] subscribe(final Topic[] topics) throws Exception { return this.next.subscribe(topics).await(); }
public byte[] subscribe(final Topic[] topics) throws Exception { return this.next.subscribe(topics).await(); }
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.start(monitor); this.executor = Executors.newSingleThreadExecutor(new SubscribersThreadFactory()); LOGGER.info("Receiver connecting to MQTT broker at '" + getBrokerInfo() + "'..."); connection = getConnection(); LOGGER.info("Receiver connected to MQTT broker."); // Subscribe to chosen topic. Topic[] topics = { new Topic(getTopic(), QoS.AT_LEAST_ONCE) }; try { Future<byte[]> future = connection.subscribe(topics); future.await(); LOGGER.info("Subscribed to events on MQTT topic: " + getTopic()); } catch (Exception e) { throw new SiteWhereException("Exception while attempting to subscribe to MQTT topic: " + getTopic(), e); } // Handle message processing in separate thread. executor.execute(new MqttSubscriptionProcessor()); }
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { super.start(monitor); this.subscriptionExecutor = Executors.newSingleThreadExecutor(new SubscribersThreadFactory()); this.processorsExecutor = Executors.newFixedThreadPool(getNumThreads(), new ProcessorsThreadFactory()); // Set up metrics. this.receivedEvents = createMeterMetric(getMetricPrefix() + "receivedEvents"); getLogger().info("Receiver connecting to MQTT broker at '" + getBrokerInfo() + "'..."); connection = getConnection(); getLogger().info("Receiver connected to MQTT broker."); getLogger().info("Suscribing using QoS: " + getQos()); QoS qos = qosFromConfig(getQos()); // Subscribe to chosen topic. Topic[] topics = { new Topic(getTopic(), qos) }; try { Future<byte[]> future = connection.subscribe(topics); future.await(); getLogger().info(EventSourcesMessages.SUBSCRIBED_TO_EVENTS_MQTT, getTopic(), getNumThreads()); } catch (Exception e) { throw new SiteWhereException("Exception while attempting to subscribe to MQTT topic: " + getTopic(), e); } // Handle message processing in separate thread. subscriptionExecutor.execute(new MqttSubscriptionProcessor()); }