use of com.ibm.streamsx.topology.TSink in project streamsx.topology by IBMStreams.
the class MqttStreamsTest method testConfigParams.
@Test
public void testConfigParams() throws Exception {
checkAssumes();
setupDebug();
Topology top = new Topology("testConfigParams");
MsgGenerator mgen = new MsgGenerator(top.getName());
String clientId = newPubClientId(top.getName());
String topicVal = getMqttTopics()[0];
Supplier<String> topic = new Value<String>(topicVal);
List<Message> msgs = createMsgs(mgen, null);
// Test more config properties to be sure we don't blow up
Map<String, Object> config = createConfig(clientId);
config.put("defaultQOS", 1);
config.put("keepAliveInterval", 20);
config.put("commandTimeoutMsec", 30000L);
config.put("reconnectDelayMsec", 5000L);
config.put("receiveBufferSize", 10);
config.put("reconnectionBound", 20);
config.put("retain", false);
config.put("userID", System.getProperty("user.name"));
config.put("password", "foobar");
config.put("trustStore", "/tmp/no-such-trustStore");
config.put("trustStorePassword", "woohoo");
config.put("keyStore", "/tmp/no-such-keyStore");
config.put("keyStorePassword", "woohoo");
MqttStreams mqtt = new MqttStreams(top, config);
Map<String, Object> pcfg = mqtt.getConfig();
for (String s : config.keySet()) assertEquals("property " + s, config.get(s), pcfg.get(s));
TStream<Message> msgsToPublish = top.constants(msgs).modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
TSink sink = mqtt.publish(msgsToPublish, topic);
TStream<Message> rcvdMsgs = mqtt.subscribe(topic);
// for validation...
rcvdMsgs.print();
// bundle construction fails for unrecognized or incorrectly typed SPL op params
File actBundle = (File) StreamsContextFactory.getStreamsContext(StreamsContext.Type.BUNDLE).submit(top, getConfig()).get(15, TimeUnit.SECONDS);
System.out.println("bundle " + actBundle.getAbsolutePath());
assertTrue(actBundle != null);
actBundle.delete();
assertTrue(sink != null);
}
use of com.ibm.streamsx.topology.TSink in project streamsx.topology by IBMStreams.
the class MqttStreamsTest method testMsgImplProducer.
@Test
public void testMsgImplProducer() throws Exception {
checkAssumes();
setupDebug();
Topology top = new Topology("testMsgImplProducer");
MsgGenerator mgen = new MsgGenerator(top.getName());
String subClientId = newSubClientId(top.getName());
String pubClientId = newPubClientId(top.getName());
String topicVal = getMqttTopics()[0];
Supplier<String> topic = new Value<String>(topicVal);
List<Message> msgs = createMsgs(mgen, null);
List<String> expectedAsString = mapList(modifyList(msgs, setTopic(topicVal)), msgToJSONStringFunc());
// Test producer that takes TStream<SimpleMessage> and an explicit topic.
MqttStreams producer = new MqttStreams(top, createConfig(pubClientId));
MqttStreams consumer = new MqttStreams(top, createConfig(subClientId));
TStream<Message> msgsToPublish = top.constants(msgs).modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
TSink sink = producer.publish(msgsToPublish, topic);
TStream<Message> rcvdMsgs = consumer.subscribe(topic);
// for validation...
rcvdMsgs.print();
// just our msgs
rcvdMsgs = selectMsgs(rcvdMsgs, mgen.pattern());
TStream<String> rcvdAsString = rcvdMsgs.transform(msgToJSONStringFunc());
if (testBuildOnly(top))
return;
completeAndValidate(subClientId, top, rcvdAsString, SEC_TIMEOUT, expectedAsString.toArray(new String[0]));
assertTrue(sink != null);
}
use of com.ibm.streamsx.topology.TSink in project streamsx.topology by IBMStreams.
the class MqttStreamsTest method testSubtypeImplicitTopicProducer.
@Test
public void testSubtypeImplicitTopicProducer() throws Exception {
checkAssumes();
setupDebug();
Topology top = new Topology("testSubtypeImplicitTopicProducer");
MsgGenerator mgen = new MsgGenerator(top.getName());
String subClientId = newSubClientId(top.getName());
String pubClientId = newPubClientId(top.getName());
String topic = getMqttTopics()[0];
List<MyMsgSubtype> msgs = new ArrayList<>();
for (Message m : createMsgs(mgen, topic)) {
msgs.add(new MyMsgSubtype(m.getMessage(), m.getTopic()));
}
List<String> expectedAsString = mapList(msgs, subtypeMsgToJSONStringFunc(null));
// Test producer that takes a TStream<MyMsgSubtype> implicit topic
MqttStreams producer = new MqttStreams(top, createConfig(pubClientId));
MqttStreams consumer = new MqttStreams(top, createConfig(subClientId));
TStream<MyMsgSubtype> msgsToPublish = top.constants(msgs).asType(MyMsgSubtype.class).modify(new InitialDelay<MyMsgSubtype>(PUB_DELAY_MSEC));
TSink sink = producer.publish(msgsToPublish);
TStream<Message> rcvdMsgs = consumer.subscribe(new Value<String>(topic));
// for validation...
rcvdMsgs.print();
// just our msgs
rcvdMsgs = selectMsgs(rcvdMsgs, mgen.pattern());
TStream<String> rcvdAsString = rcvdMsgs.transform(msgToJSONStringFunc());
if (testBuildOnly(top))
return;
completeAndValidate(subClientId, top, rcvdAsString, SEC_TIMEOUT, expectedAsString.toArray(new String[0]));
assertTrue(sink != null);
}
use of com.ibm.streamsx.topology.TSink in project streamsx.topology by IBMStreams.
the class MqttStreamsTest method testReusableApp.
@Test
public void testReusableApp() throws Exception {
checkAssumes();
setupDebug();
Topology top = new Topology("testReusableApp");
MsgGenerator mgen = new MsgGenerator(top.getName());
String subClientId = newSubClientId(top.getName());
String pubClientId = newPubClientId(top.getName());
String topic = getMqttTopics()[0];
List<Message> msgs = createMsgs(mgen, null);
// Test an app structured more as a "reusable asset" - i.e.,
// where the mqtt connection info (URI, authInfo) and
// topic are defined at submission time.
// define/create the app's submission parameters
ParameterHelper params = new ParameterHelper(top);
params.definitions().put("mqtt.serverURI", String.class);
params.definitions().put("mqtt.userID", System.getProperty("user.name"));
params.definitions().put("mqtt.password", String.class);
params.definitions().put("mqtt.pub.topic", String.class);
params.definitions().put("mqtt.sub.topic", String.class);
params.createAll();
// add the actual param values for our call to submit()
Map<String, Object> submitParams = new HashMap<>();
submitParams.put("mqtt.serverURI", "tcp://localhost:1883");
// submitParams.put("mqtt.userID", System.getProperty("user.name"));
submitParams.put("mqtt.password", "myMosquittoPw");
submitParams.put("mqtt.pub.topic", topic);
submitParams.put("mqtt.sub.topic", topic);
getConfig().put(ContextProperties.SUBMISSION_PARAMS, submitParams);
// Produce and consume the msgs
Map<String, Object> pconfig = createConfig(pubClientId);
addMqttParams(pconfig, false, params);
Map<String, Object> cconfig = createConfig(subClientId);
addMqttParams(cconfig, true, params);
MqttStreams producer = new MqttStreams(top, pconfig);
MqttStreams consumer = new MqttStreams(top, cconfig);
TStream<Message> msgsToPublish = top.constants(msgs).modify(new InitialDelay<Message>(PUB_DELAY_MSEC));
TSink sink = producer.publish(msgsToPublish, params.getString("mqtt.pub.topic"));
TStream<Message> rcvdMsgs = consumer.subscribe(params.getString("mqtt.sub.topic"));
// for validation...
rcvdMsgs.print();
// just our msgs
rcvdMsgs = selectMsgs(rcvdMsgs, mgen.pattern());
TStream<String> rcvdAsString = rcvdMsgs.transform(msgToJSONStringFunc());
msgs = modifyList(msgs, setTopic(topic));
List<String> expectedAsString = mapList(msgs, msgToJSONStringFunc());
if (testBuildOnly(top))
return;
completeAndValidate(subClientId, top, rcvdAsString, SEC_TIMEOUT, expectedAsString.toArray(new String[0]));
assertTrue(sink != null);
}
use of com.ibm.streamsx.topology.TSink in project streamsx.health by IBMStreams.
the class PatientManipulatorService method build.
public void build() {
TStream<Observation> obsStream = null;
for (String topic : topics) {
TStream<Observation> tstream = SubscribeConnector.subscribe(topo, topic.trim());
if (obsStream == null)
obsStream = tstream;
else
obsStream = obsStream.union(tstream);
}
TSink controlSink = SPLStreams.subscribe(topo, CONTROL_INPUT_TOPIC, JSONSchemas.JSON).convert(t -> t.getString(0)).asType(String.class).sink(new PatientController());
TStream<Observation> modifiedObs = obsStream.modify(new Manipulator());
controlSink.colocate(modifiedObs);
PublishConnector.publishObservation(modifiedObs, getPublishedTopic());
}
Aggregations