Github user queeniema commented on a diff in the pull request:

    
https://github.com/apache/incubator-edgent-website/pull/97#discussion_r155388008
  
    --- Diff: site/docs/power-of-edgent.md ---
    @@ -0,0 +1,417 @@
    +---
    +title: The Power of Apache Edgent
    +---
    +
    +Edgent is designed to accellerate your development of event driven 
flow-graph
    +style analytic applications running on edge devices.  This is achieved by
    +Edgent's combination of API, connectors, basic analytics, utilities, and 
openness!
    +
    +Let's have some fun with a shallow but broad view into what you
    +can do in a few of lines of code... an introduction to Edgent's 
capabilities via
    +a series of terse code fragments.
    +
    +See the [Getting Started Guide](edgent-getting-started) for a step by step 
introduction,
    +and information about full samples and recipies.
    +
    +Let's start with a complete application that periodically samples a sensor
    +and publishes its values to an Enterprise IoT Hub in less than 10 lines of 
code
    +
    +```java
    +public class ImpressiveEdgentExample {
    +  public static void main(String[] args) {
    +    DirectProvider provider = new DirectProvider();
    +    Topology top = provider.newTopology();
    +
    +    IotDevice iotConnector = IotpDevice.quickstart(top, 
"edgent-intro-device-2");
    +    // open 
https://quickstart.internetofthings.ibmcloud.com/#/device/edgent-intro-device-2
    +
    +    // ingest -> transform -> publish
    +    TStream<Double> readings = top.poll(new SimulatedTemperatureSensor(), 
1, TimeUnit.SECONDS);
    +    TStream<JsonObject> events = 
readings.map(JsonFunctions.valueOfNumber("temp"));
    +    iotConnector.events(events, "readingEvents", QoS.FIRE_AND_FORGET);
    +
    +    provider.submit(top);
    +  }
    +}
    +```
    +
    +Ok, that was 11 lines and it omitted the imports, but there are only 7 
lines in main()!
    +
    +That leveraged the [IotpDevice]({{ site.docsurl 
}}/index.html?org/apache/{{ site.data.project.unix_name 
}}/connectors/iotp/IotpDevice.html)
    +connector to the 
    +IBM Watson IoT Platform and the platform's Quickstart feature. 
    +The value of its Quickstart feature is no account or device 
    +preregistration and the ability to open a browser to see the
    +data being published.  Great to quickly get started.
    +
    +Hopefully that had enough of a wow factor to encourage you
    +to keep reading!
    +
    +### Connectors, Ingest and Sink
    +
    +Edgent Applications need to create streams of data from external entities,
    +termed ingest, and sink streams of data to external entities.  
    +There are primitives for those operations and a collection of
    +connectors to common external entities,
    +more Connectors contributions are welcome!
    +
    +Connectors are just code that make it easier for an Edgent application
    +to integrate with an external entity.  They use Edgent ingest primitives
    +like (`Topology.poll()`, `Topology.events()`, etc), and `TStream.sink()`
    +like any other Edgent code.  A connector may provide `Supplier` and 
    +`Consumer` functions, for ingest and sink respectively, that an 
    +application can use directly with the Edgent API.
    +
    +OK... fewer words, more code!
    +
    +You've already seen publishing using the `IotpDevice` connector.
    +
    +Want to receive [IotDevice]({{ site.docsurl }}/index.html?org/apache/{{ 
site.data.project.unix_name }}/connectors/iot/IotDevice.html) device commands? 
Simple!
    +
    +```java
    +    TStream<JsonObject> cmds = iotConnector.commands();
    +    cmds.sink(cmd -> System.out.println("I should handle received cmd: 
"+cmd));
    +
    +    or
    +    TStream<JsonObject> xzyCmds = iotConnector.command("xyzCmds");
    +```
    +
    +There's an [IotGateway]({{ site.docsurl }}/index.html?org/apache/{{ 
site.data.project.unix_name }}/connectors/iot/IotGateway.html) device model too.
    +
    +Don't want no stinkin `IotDevice` model and just
    +want to pub/sub to an MQTT server?  No worries! Use the [MqttStreams]({{ 
site.docsurl }}/index.html?org/apache/{{ site.data.project.unix_name 
}}/connectors/mqtt/MqttStreams.html) connector
    +
    +```java
    +    //IotDevice iotConnector = IotpDevice.quickstart(top, 
"edgent-intro-device-2");
    +    MqttStreams iotConnector = new MqttStreams(top, 
"ssl://myMqttServer:8883", "my-device-client-id");
    +
    +    ...
    +
    +    //iotConnector.events(events, "readingEvents", QoS.FIRE_AND_FORGET);
    +    iotConnector.publish(events, "readingEvents", QoS.FIRE_AND_FORGET, 
false);
    +
    +    TStream<JsonObject> xyzTopicMsgs = iotConnector.subscribe("xyzTopic");
    +```
    +
    +Want to connect to Kafka?  Use the [KafkaProducer]({{ site.docsurl 
}}/index.html?org/apache/{{ site.data.project.unix_name 
}}/connectors/kafka/KafkaProducer.html) and [KafkaConsumer]({{ site.docsurl 
}}/index.html?org/apache/{{ site.data.project.unix_name 
}}/connectors/kafka/KafkaConsumer.html) connectors with similar ease.
    +
    +There's a [JdbcStreams]({{ site.docsurl }}/index.html?org/apache/{{ 
site.data.project.unix_name }}/connectors/jdbc/JdbcStreams.html) connector too.
    +
    +Want to sink a `TStream` to rolling text files?  Use the [FileStreams]({{ 
site.docsurl }}/index.html?org/apache/{{ site.data.project.unix_name 
}}/connectors/file/FileStreams.html) connector.
    +
    +```java
    +    new File("/tmp/MY-DEMO-FILES").mkdir();
    +    FileStreams.textFileWriter(events.asString(), () -> 
"/tmp/MY-DEMO-FILES/READINGS");
    +
    +    // tail -f /tmp/MY-DEMO-FILES/.READINGS
    +```
    +
    +Or watch for, ingest and process text files?  [Csv]({{ site.docsurl 
}}/index.html?org/apache/{{ site.data.project.unix_name 
}}/connectors/csv/Csv.html) can be useful if your input lines of comma 
separated values
    +
    +```java
    +   String watchedDir = "/some/directory/path";
    +   List<String> csvFieldNames = ...
    +   TStream<String> pathnames = FileStreams.directoryWatcher(top, () -> 
watchedDir, null);
    +   TStream<String> lines = FileStreams.textFileReader(pathnames);
    +   TStream<JsonObject> parsedLines = lines.map(line -> 
Csv.toJson(Csv.parseCsv(line), csvFieldNames));
    +```
    +
    +Want to sink to a command's stdin?  Use the [CommandStreams]({{ 
site.docsurl }}/index.html?org/apache/{{ site.data.project.unix_name 
}}/connectors/command/CommandStreams.html) connector
    +
    +```java
    +    TStream<MyEvent> events = ...
    +    ProcessBuilder cmd = new ProcessBuilder("cat").redirectOutput(new 
File("/dev/stdout"));
    +    CommandStreams.sink(events.asString(), cmd);
    +```
    +
    +Or ingest a command's stdout/err?
    +
    +```java
    +    ProcessBuilder cmd = new ProcessBuilder("date", "-R");
    +    TStream<List<String>> readings = CommandStreams.periodicSource(top, 
cmd, 1, TimeUnit.SECONDS);
    +
    +    TStream<JsonObject> events =
    +        readings
    +          .flatMap(list -> list)
    +          .map(JsonFunctions.valueOfString("date"));
    +    
    +    // also note TStream support for a fluent programming style
    +    // and use of TStream.flatmap() to transform in input list to
    +    // an output list and then add each output list item as a separate
    +    // tuple to the output stream
    +```
    +
    +
    +Want to sink to a log via slf4j or another logging system?  Just do it!
    --- End diff --
    
    nit: "slf4j" --> "SLF4J"


---

Reply via email to