|
| 1 | +# Infrakit Event Repeater Application |
| 2 | +This is a sample of Infrakit Application. |
| 3 | +It enable to repeat events from event plugin to MQTT brocker. |
| 4 | + |
| 5 | +## Get Start |
| 6 | + |
| 7 | +### Prepare |
| 8 | +Start event plugin and mqtt broker |
| 9 | +``` |
| 10 | +$ ./build/infrakit-event-time |
| 11 | +$ docker run -it --rm -p 1883:1883 eclipse-mosquitto |
| 12 | +``` |
| 13 | + |
| 14 | +## Run event repeater |
| 15 | + |
| 16 | +``` |
| 17 | +$ ./build/infrakit-application-repeater -h |
| 18 | +Event Repeater Application plugin |
| 19 | +
|
| 20 | +Usage: |
| 21 | + ./build/infrakit-application-repeater [flags] |
| 22 | +
|
| 23 | +Flags: |
| 24 | + --allowall Allow all event from source and repeat the event to sink as same topic name. default: false |
| 25 | + --log int Logging level. 0 is least verbose. Max is 5 (default 4) |
| 26 | + --name string Application name to advertise for discovery (default "app-event-repeater") |
| 27 | + --sink string Event sink address. default: localhost:1883 (default "localhost:1883") |
| 28 | + --sinkprotocol string Event sink protocol. Now only mqtt and stderr is implemented. (default "mqtt") |
| 29 | + --source string Event sourve address. (default "event-plugin") |
| 30 | +
|
| 31 | +$ ./build/infrakit-application-repeater --source ~/.infrakit/plugins/event-time --sink tcp://localhost:1883 |
| 32 | +``` |
| 33 | + |
| 34 | +Now your app connected to event plugin and mqtt broker. |
| 35 | +If you set `—-allowall`, your app subscribe ‘.’ Topic from event and publish all events to broker with original topic. |
| 36 | +You can specify repeat topics with infrakit command like below. |
| 37 | + |
| 38 | +``` |
| 39 | +$ ./build/infrakit application update -h |
| 40 | +
|
| 41 | +
|
| 42 | +___ ________ ________ ________ ________ ___ __ ___ _________ |
| 43 | +|\ \|\ ___ \|\ _____\\ __ \|\ __ \|\ \|\ \ |\ \|\___ ___\ |
| 44 | +\ \ \ \ \\ \ \ \ \__/\ \ \|\ \ \ \|\ \ \ \/ /|\ \ \|___ \ \_| |
| 45 | + \ \ \ \ \\ \ \ \ __\\ \ _ _\ \ __ \ \ ___ \ \ \ \ \ \ |
| 46 | + \ \ \ \ \\ \ \ \ \_| \ \ \\ \\ \ \ \ \ \ \\ \ \ \ \ \ \ \ |
| 47 | + \ \__\ \__\\ \__\ \__\ \ \__\\ _\\ \__\ \__\ \__\\ \__\ \__\ \ \__\ |
| 48 | + \|__|\|__| \|__|\|__| \|__|\|__|\|__|\|__|\|__| \|__|\|__| \|__| |
| 49 | +
|
| 50 | +
|
| 51 | +Update application's resouce |
| 52 | +
|
| 53 | +Usage: |
| 54 | + ./build/infrakit application update [flags] |
| 55 | +
|
| 56 | +Flags: |
| 57 | + --op int update operation 1: Add, 2: Delete, 3: Update, 4: Read(default) (default 3) |
| 58 | + --resource string target resource |
| 59 | + --value string update value |
| 60 | +
|
| 61 | +Global Flags: |
| 62 | + -H, --host stringSlice host list. Default is local sockets |
| 63 | + --httptest.serve string if non-empty, httptest.NewServer serves on this address and blocks |
| 64 | + --log int log level (default 4) |
| 65 | + --log-caller include caller function (default true) |
| 66 | + --log-format string log format: logfmt|term|json (default "term") |
| 67 | + --log-stack include caller stack |
| 68 | + --log-stdout log to stdout |
| 69 | + --name string Name of plugin |
| 70 | +$ ./build/infrakit application update --name app-event-repeater --op 1 --resource event --value '[{"sourcetopic":"timer/sec/1","sinktopic":"/time/1s"},{"sourcetopic":"timer/msec/500","sinktopic":"/time/500m"}]' |
| 71 | +``` |
| 72 | + |
| 73 | +Target events are described json style. |
| 74 | +Then you can delete registerd event. |
| 75 | + |
| 76 | +``` |
| 77 | +./build/infrakit application update --name app-event-repeater --op 2 --resource event --value '[{"sourcetopic":"timer/sec/1”}]’ |
| 78 | +``` |
| 79 | +Repeated events are encoded with byte. |
| 80 | +You can decode it like below. |
| 81 | + |
| 82 | +``` |
| 83 | +any := types.AnyBytes(SUBSCRIVED_MESSAGE.Payload()) |
| 84 | +subevent := event.Event{} |
| 85 | +err := any.Decode(&subevent) |
| 86 | +``` |
0 commit comments