Search in sources :

Example 26 with Message

use of com.ibm.streamsx.topology.tuple.Message in project streamsx.topology by IBMStreams.

the class MqttStreamsTest method testImplicitTopicProducer.

@Test
public void testImplicitTopicProducer() throws Exception {
    checkAssumes();
    setupDebug();
    Topology top = new Topology("testImplicitTopicProducer");
    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, topic);
    List<String> expectedAsString = mapList(msgs, msgToJSONStringFunc());
    // Test producer that takes an arbitrary TStream<T> and implicit 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);
    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);
}
Also used : TSink(com.ibm.streamsx.topology.TSink) MqttStreams(com.ibm.streamsx.topology.messaging.mqtt.MqttStreams) SimpleMessage(com.ibm.streamsx.topology.tuple.SimpleMessage) Message(com.ibm.streamsx.topology.tuple.Message) Topology(com.ibm.streamsx.topology.Topology) TestTopology(com.ibm.streamsx.topology.test.TestTopology) Test(org.junit.Test)

Aggregations

Message (com.ibm.streamsx.topology.tuple.Message)26 SimpleMessage (com.ibm.streamsx.topology.tuple.SimpleMessage)25 Topology (com.ibm.streamsx.topology.Topology)20 Test (org.junit.Test)19 TestTopology (com.ibm.streamsx.topology.test.TestTopology)18 Value (com.ibm.streamsx.topology.logic.Value)15 TSink (com.ibm.streamsx.topology.TSink)13 MqttStreams (com.ibm.streamsx.topology.messaging.mqtt.MqttStreams)12 ArrayList (java.util.ArrayList)12 KafkaConsumer (com.ibm.streamsx.topology.messaging.kafka.KafkaConsumer)8 KafkaProducer (com.ibm.streamsx.topology.messaging.kafka.KafkaProducer)8 InitialDelay (com.ibm.streamsx.topology.test.InitialDelay)7 HashMap (java.util.HashMap)6 SPLStream (com.ibm.streamsx.topology.spl.SPLStream)4 JSONObject (com.ibm.json.java.JSONObject)3 File (java.io.File)2