@Test public void testSubscribe() throws Exception { // fill the model with data SignalKModel model = SignalKModelFactory.getMotuTestInstance(); model.putAll(TestHelper.getBasicModel().getFullData()); // create STOMP connection StompConnection connection = new StompConnection(); connection.open("localhost", 61613); logger.debug("Opened STOMP socket, connecting.. "); StompFrame connect = connection.connect("system", "manager"); // StompFrame connect = connection.receive(); if (!connect.getAction().equals(Stomp.Responses.CONNECTED)) { throw new Exception("Not connected"); } logger.debug("connected" + connect.getHeaders()); // create a private receive queue String uuid = UUID.randomUUID().toString(); connection.subscribe( "/queue/signalk." + uuid + ".vessels.motu.navigation", Subscribe.AckModeValues.AUTO); // subscribe Json subMsg = getSubscribe( "vessels." + SignalKConstants.self, "navigation", 1000, 0, FORMAT_DELTA, POLICY_FIXED); subMsg.set( nz.co.fortytwo.signalk.util.ConfigConstants.OUTPUT_TYPE, nz.co.fortytwo.signalk.util.ConfigConstants.OUTPUT_STOMP); subMsg.set(WebsocketConstants.CONNECTION_KEY, uuid); HashMap<String, String> headers = new HashMap<String, String>(); // queue>signalk.3202a939-1681-4a74-ad4b-3a90212e4f33.vessels.motu.navigation // set private queue to receive data headers.put("reply-to", "/queue/signalk." + uuid + ".vessels.motu.navigation"); headers.put(WebsocketConstants.CONNECTION_KEY, uuid); connection.send("/queue/signalk.put", subMsg.toString(), null, headers); // listen for messages StompFrame message = connection.receive(); logger.debug("Body: " + message.getBody()); assertNotNull(message); Json reply = Json.read(message.getBody()); assertNotNull(reply.at(SignalKConstants.CONTEXT)); assertNotNull(reply.at(SignalKConstants.UPDATES)); // unsubscribe subMsg = getSubscribe( "vessels." + SignalKConstants.self, "navigation", 1000, 0, FORMAT_DELTA, POLICY_FIXED); connection.send("/queue/signalk.subscribe", subMsg.toString(), null, headers); connection.unsubscribe("/queue/signalk." + uuid + ".vessels.motu.navigation"); // disconnect connection.disconnect(); }
@Test public void testSendingGetFull() throws Exception { // fill the model with data SignalKModel model = SignalKModelFactory.getMotuTestInstance(); model.putAll(TestHelper.getBasicModel().getFullData()); // create STOMP connection StompConnection connection = new StompConnection(); connection.open("localhost", 61613); logger.debug("Opened STOMP socket, connecting.. "); StompFrame connect = connection.connect("system", "manager"); // StompFrame connect = connection.receive(); if (!connect.getAction().equals(Stomp.Responses.CONNECTED)) { throw new Exception("Not connected"); } logger.debug("connected" + connect.getHeaders()); // create a private receive queue String uuid = UUID.randomUUID().toString(); connection.subscribe( "/queue/signalk." + uuid + "." + vessels_dot_self_dot + env_wind, Subscribe.AckModeValues.AUTO); latch.await(2, TimeUnit.SECONDS); // send list Json subMsg = getGet("vessels." + SignalKConstants.self, env_wind + ".*", SignalKConstants.FORMAT_FULL); HashMap<String, String> headers = new HashMap<String, String>(); logger.debug("sending" + subMsg); // queue>signalk.3202a939-1681-4a74-ad4b-3a90212e4f33.vessels.motu.navigation // set private queue to receive data headers.put("reply-to", "/queue/signalk." + uuid + dot + vessels_dot_self_dot + env_wind); headers.put(WebsocketConstants.CONNECTION_KEY, uuid); connection.send("/queue/signalk.put", subMsg.toString(), null, headers); // listen for messages StompFrame message = connection.receive(); logger.debug("Body: " + message.getBody()); assertNotNull(message); Json reply = Json.read(message.getBody()); assertNotNull(reply.at(SignalKConstants.vessels)); assertNotNull(reply.at(SignalKConstants.vessels).at(SignalKConstants.self).at(env).at("wind")); // unsubscribe connection.unsubscribe("/queue/signalk." + uuid + "." + vessels_dot_self_dot + env_wind); // disconnect connection.disconnect(); }
public void process(Exchange exchange) throws Exception { if (exchange.getIn().getBody() == null) return; if (logger.isDebugEnabled()) logger.debug("Processing, class=" + exchange.getIn().getBody().getClass()); // TODO: add more filters here if (exchange.getIn().getBody() instanceof Json) { Json json = (Json) exchange.getIn().getBody(); // remove _arduino try { json.at(SignalKConstants.vessels).at(SignalKConstants.self).delAt("_arduino"); } catch (NullPointerException npe) { } // remove _config try { json.at(SignalKConstants.vessels).at(SignalKConstants.self).delAt("_config"); } catch (NullPointerException npe) { } exchange.getIn().setBody(json.toString()); } if (exchange.getIn().getBody() instanceof SignalKModel) { SignalKModel model = (SignalKModel) exchange.getIn().getBody(); // remove _arduino try { model.put(SignalKConstants.vessels_dot_self_dot + "_arduino", null); } catch (NullPointerException npe) { } // remove _config try { model.put(SignalKConstants.vessels_dot_self_dot + "_config", null); } catch (NullPointerException npe) { } exchange.getIn().setBody(ser.write(model)); } if (logger.isDebugEnabled()) { logger.debug("Outputting:" + exchange.getIn().getHeaders()); logger.debug("Outputting:" + exchange.getIn()); } }