Giter VIP home page Giter VIP logo

time-averager's Introduction

Time Averager Example

This repository contains a sample streaming function that can be used with the riff streaming POC. It is simple enough to be usable as both a request/reply sample and a stateful streaming sample.

Prerequisites

These samples assume you have the latest patched riff system, riff CLI reset branch, liiklus running and exposed as a k8s service, as well as a configured kafka provider and have modified the function builder to use ericbottard/builder:streaming-grpc.

Compile the Function

riff function create time-averager \
	--git-repo https://github.com/projectriff-samples/time-averager.git \
	--handler com.acme.TimeAverager \
	--image $KO_DOCKER_REPO/time-averager

Use as Request/Reply

Create a handler for the function:

riff handler create time-averager --function-ref time-averager

Invoke it a couple of times. The average of a single number is the number itself:

riff handler invoke time-averager --text -- -d 48 -H 'Accept: application/json' -w '\n'

48.0

riff handler invoke time-averager --text -- -d 50 -H 'Accept: application/json' -w '\n'

50.0

Use as a Streaming Sample

Create two streams

riff stream create --provider kafka-provider numbers
riff stream create --provider kafka-provider avgs

Create a streaming processor for the function:

riff processor create time-averager --function-ref time-averager --input numbers --output avgs

Using the riff liiklus-client, in two separate terminals:

Setup a consumer:

java -jar target/liiklus-client-1.0.0-SNAPSHOT.jar --consumer my.liiklus.host:6565 avgs

Setup a producer:

java -jar target/liiklus-client-1.0.0-SNAPSHOT.jar --producer my.liiklus.host:6565 numbers

Then, in the producer window, and in rather quick succession, enter numbers and hit [ENTER].

time-averager's People

Contributors

ericbottard avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.