Skip to content

Commit

Permalink
Adding examples for CDC and IoT (#397)
Browse files Browse the repository at this point in the history
* bun init

* a working version

* clean up and able to demo

* avoid hardcode IP and stream name

* update README(s) and CDC example
  • Loading branch information
jovezhong authored Dec 11, 2023
1 parent 2dbdb0d commit 27e1e8e
Show file tree
Hide file tree
Showing 16 changed files with 507 additions and 4 deletions.
10 changes: 9 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

This folder lists some examples to run Proton in various use cases. For more real-world examples, please check https://docs.timeplus.com/showcases

- ecommerce: a combination of Proton, Redpanda, owl-shop and Redpanda Console. Owl Shop is an imaginary ecommerce shop that simulates microservices exchanging data via Apache Kafka. Sample data streams are: clickstreams(frontend events), customer info, customer orders. [Learn more](https://docs.timeplus.com/proton-kafka#tutorial)
- awesome-sensor-logger: You can install the free app for your phone, https://github.com/tszheichoi/awesome-sensor-logger, and use a proxy server to redirect the IoT sensor data to your local Proton, or even visualize it with Grafana.

- carsharing: just two containers: Proton and [Chameleon](https://github.com/timeplus-io/chameleon). It is an imginary carsharing company. Sensors are equipped in each car to report car locations. The customers use the mobile app to find available cars nearby, book them, unlock them and hit the road. At the end of the trip, the customer parks the car, locks it, and ends the trip. The payment will proceed automatically with the registered credit card. [Learn more](https://docs.timeplus.com/usecases)

- cdc: demonstrates how to use Debezium to sync database changes from MySQL to Proton, via Redpanda and show live updates(UPSERT and DELETE) in Proton via changelog stream.

- ecommerce: a combination of Proton, Redpanda, owl-shop and Redpanda Console. Owl Shop is an imaginary ecommerce shop that simulates microservices exchanging data via Apache Kafka. Sample data streams are: clickstreams(frontend events), customer info, customer orders. [Learn more](https://docs.timeplus.com/proton-kafka#tutorial)

- fraud_detection: demonstrates how to leverage proton to build a real-time fraud detection where proton is used as a real-time feature store.

- hackernews: just two containers: Proton and [a bytewax-based data loader](https://github.com/timeplus-io/proton-python-driver/tree/develop/example/bytewax). Inspired by https://bytewax.io/blog/polling-hacker-news, you can call Hacker News HTTP API with Bytewax and send latest news to Proton for SQL-based analysis.

- grafana: an example of how to use Grafana to connect to Proton and visualize the query results.

- jdbc: demonstrates how to connect to Proton via JDBC using DBeaver or Metabase.
15 changes: 15 additions & 0 deletions examples/awesome-sensor-logger/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
node_modules
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
README.md
LICENSE
.vscode
Makefile
helm-charts
.env
.editorconfig
.idea
coverage*
175 changes: 175 additions & 0 deletions examples/awesome-sensor-logger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
37 changes: 37 additions & 0 deletions examples/awesome-sensor-logger/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 as base
WORKDIR /usr/src/app

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/
RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/
RUN cd /temp/prod && bun install --frozen-lockfile --production

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM base AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .
COPY src src

ENV NODE_ENV=production

# copy production dependencies and source code into final image
FROM base AS release
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/app/index.ts .
COPY --from=prerelease /usr/src/app/src/index.routes.ts src/index.routes.ts
COPY --from=prerelease /usr/src/app/package.json .

# run the app
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "index.ts" ]
15 changes: 15 additions & 0 deletions examples/awesome-sensor-logger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# awesome-sensor-logger

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.0.15. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
Binary file added examples/awesome-sensor-logger/bun.lockb
Binary file not shown.
19 changes: 19 additions & 0 deletions examples/awesome-sensor-logger/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.7'
services:
proton:
image: ghcr.io/timeplus-io/proton:latest
pull_policy: always
ports:
- 3218:3218 #http port for JDBC driver, default streaming mode
- 8123:8123 #http port for JDBC driver, default batch mode
- 8463:8463 #tcp port for go driver or grafana plugin

proxy:
image: timeplus/sensor-logger-proxy
ports:
- 8000:3000 #expose internal port 3000 as 8000, avoiding conflicts with Grafana. This will forward HTTP POST to proton:3218
environment:
HOST: proton
STREAM: phone
depends_on:
- proton
5 changes: 5 additions & 0 deletions examples/awesome-sensor-logger/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { init } from '@stricjs/app';

init({
routes: ['./src']
});
19 changes: 19 additions & 0 deletions examples/awesome-sensor-logger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "awesome-sensor-logger",
"module": "index.ts",
"type": "module",
"scripts": {
"start": "bun run index.ts"
},
"devDependencies": {
"bun-types": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"@stricjs/app": "^1.0.0-alpha",
"@stricjs/router": "^5.0.6",
"@stricjs/utils": "^1.6.1"
}
}
15 changes: 15 additions & 0 deletions examples/awesome-sensor-logger/src/index.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { routes } from '@stricjs/app';

export function main() {
const protonIngestEndpoint = `http://${process.env.HOST}:3218/proton/v1/ingest/streams/${process.env.STREAM}`;
return routes()
.post('/', c => {
return c.text().then(a => {
return fetch(protonIngestEndpoint, {
method: "POST",
body: `{"columns": ["raw"],"data": [["${a.replaceAll('"', '\\\"')}"]]}`,
headers: { "Content-Type": "application/json" },
}).then(protonResp => new Response('status code ' + protonResp.status));
});
})
}
22 changes: 22 additions & 0 deletions examples/awesome-sensor-logger/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
"moduleDetection": "force",
"allowImportingTsExtensions": true,
"noEmit": true,
"composite": true,
"strict": true,
"downlevelIteration": true,
"skipLibCheck": true,
"jsx": "react-jsx",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"types": [
"bun-types" // add Bun global
]
}
}
Loading

0 comments on commit 27e1e8e

Please sign in to comment.