@Override public void onOpen(Emitter emitter) throws IOException { this.emitter = emitter; try { this.mqttClient = new MqttClient(DAO.getConfig("stream.mqtt.address", "tcp://127.0.0.1:1883"), "loklak_server_subscriber"); this.mqttClient.connect(); this.mqttClient.setCallback(this); this.mqttClient.subscribe(this.channel); } catch (MqttException e) { this.emitter.close(); } }
sampleClient.subscribe(topic, qos); } catch (MqttException me) { log.error("reason " + me.getReasonCode());
client.connect(); client.setCallback(this); client.subscribe("foo"); MqttMessage message = new MqttMessage(); message.setPayload("A single message from my computer fff"
public void subscribe(String[] topicFilters) throws MqttException { int[] qos = new int[topicFilters.length]; for (int i=0; i<qos.length; i++) { qos[i] = 1; } this.subscribe(topicFilters, qos); }
public void subscribe(String[] topicFilters, IMqttMessageListener[] messageListeners) throws MqttException { int[] qos = new int[topicFilters.length]; for (int i=0; i<qos.length; i++) { qos[i] = 1; } this.subscribe(topicFilters, qos, messageListeners); }
public void subscribe(String topicFilter) throws MqttException { this.subscribe(new String[] {topicFilter}, new int[] {1}); }
public void subscribe(String topicFilter, int qos) throws MqttException { this.subscribe(new String[] {topicFilter}, new int[] {qos}); }
public void subscribe(String topicFilter, int qos, IMqttMessageListener messageListener) throws MqttException { this.subscribe(new String[] {topicFilter}, new int[] {qos}, new IMqttMessageListener[] {messageListener}); }
public void subscribe(String topicFilter, IMqttMessageListener messageListener) throws MqttException { this.subscribe(new String[] {topicFilter}, new int[] {1}, new IMqttMessageListener[] {messageListener}); }
public MqttClient buildAndConnect() throws MqttException { validateArgs(); String protocolBroker = getProtocol() + this.broker; MqttClientPersistence persistence = new MemoryPersistence(); if ( StringUtil.isEmpty( storageLevel ) ) { logChannel.logDebug( "Using Memory Storage Level" ); } else { logChannel.logDebug( "Using File Storage Level to " + storageLevel ); persistence = new MqttDefaultFilePersistence( storageLevel ); } if ( StringUtil.isEmpty( clientId ) ) { clientId = MqttAsyncClient.generateClientId(); } MqttClient client = clientFactory.getClient( protocolBroker, clientId, persistence ); client.setCallback( callback ); logChannel.logDebug( "Subscribing to topics with a quality of service level of " + qos ); logChannel.logDebug( "Server URIs is set to " + serverUris ); logChannel.logDebug( "Max Inflight is set to " + maxInflight ); logChannel.logDebug( "Automatic Reconnect is set to " + automaticReconnect ); logChannel.logDebug( loggableOptions().toString() ); client.connect( getOptions() ); if ( topics != null && !topics.isEmpty() ) { client.subscribe( topics.toArray( new String[ 0 ] ), initializedIntAray( Integer.parseInt( this.qos ) ) ); } return client; }
public void subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) throws MqttException { this.subscribe(topicFilters, qos); // add message handlers to the list for this client for (int i = 0; i < topicFilters.length; ++i) { aClient.comms.setMessageListener(topicFilters[i], messageListeners[i]); } }
public void subscribe(String[] topicFilters) throws MqttException { int[] qos = new int[topicFilters.length]; for (int i=0; i<qos.length; i++) { qos[i] = 1; } this.subscribe(topicFilters, qos); }
public void subscribe(String[] topicFilters, IMqttMessageListener[] messageListeners) throws MqttException { int[] qos = new int[topicFilters.length]; for (int i=0; i<qos.length; i++) { qos[i] = 1; } this.subscribe(topicFilters, qos, messageListeners); }
public void subscribe(String[] topicFilters, IMqttMessageListener[] messageListeners) throws MqttException { int[] qos = new int[topicFilters.length]; for (int i=0; i<qos.length; i++) { qos[i] = 1; } this.subscribe(topicFilters, qos, messageListeners); }
new DirectFieldAccessor(client).setPropertyValue("aClient", aClient); willAnswer(new CallsRealMethods()).given(client).connect(any(MqttConnectOptions.class)); willAnswer(new CallsRealMethods()).given(client).subscribe(any(String[].class), any(int[].class)); willReturn(alwaysComplete).given(aClient).connect(any(MqttConnectOptions.class), any(), any());
/** * Synchronously subscribe to a given topic. * * @param topicName The topic to subscribe to * @throws MqttException */ @Override public void subscribe(String topicName) throws MqttException { log.info("Subscribing to topic \"" + topicName + "\" on qos" + qos); mqttClient.subscribe(topicName, qos.getValue()); }
/** * Subscribe to the requested topic in a synchronous manner. * * @throws MqttException */ public void subscribe() throws MqttException { log.info("Subscribing to topic \"" + topic + "\" qos " + qos); mqttClient.subscribe(topic, qos.getValue()); //Will need to wait to receive all messages - subscriber closes on disconnect }
public void subscribe(String[] topicFilters, int[] qos, IMqttMessageListener[] messageListeners) throws MqttException { this.subscribe(topicFilters, qos); // add message handlers to the list for this client for (int i = 0; i < topicFilters.length; ++i) { aClient.comms.setMessageListener(topicFilters[i], messageListeners[i]); } }