Skip to content

Commit d3333d0

Browse files
committed
Adding the code.
0 parents  commit d3333d0

35 files changed

+1473
-0
lines changed

.bsp/sbt.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"sbt","version":"1.5.3","bspVersion":"2.0.0-M5","languages":["scala"],"argv":["/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home/bin/java","-Xms100m","-Xmx100m","-classpath","/Users/otobrglez/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/211.7442.40/IntelliJ IDEA.app.plugins/Scala/launcher/sbt-launch.jar","xsbt.boot.Boot","-bsp","--sbt-launch-jar=/Users/otobrglez/Library/Application%20Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/211.7442.40/IntelliJ%20IDEA.app.plugins/Scala/launcher/sbt-launch.jar"]}
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
version: "3.9"
2+
services:
3+
gateway:
4+
build:
5+
context: ./.docker/gateway
6+
dockerfile: Dockerfile
7+
ports:
8+
- "7070:80"
9+
- "7071:81"
10+
- "7073:83"
11+
- "7074:84"
12+
13+
cap_add:
14+
- ALL
15+
environment:
16+
- NGINX_PORT=80
17+
volumes:
18+
- ./.docker/gateway/nginx.conf:/etc/nginx/nginx.conf
19+
20+
21+
cassandra-node1:
22+
image: bitnami/cassandra:3
23+
volumes:
24+
- ./tmp/cassandra-node1:/bitnami
25+
ports:
26+
- 7000:7000
27+
- 9042:9042
28+
environment:
29+
- CASSANDRA_CLUSTER_NAME=cassandra-cluster
30+
- CASSANDRA_SEEDS=cassandra-node1,cassandra-node2,cassandra-node3
31+
- CASSANDRA_PASSWORD=cassandra
32+
- CASSANDRA_PASSWORD_SEEDER=yes
33+
34+
cassandra-node2:
35+
image: bitnami/cassandra:3
36+
volumes:
37+
- ./tmp/cassandra-node2:/bitnami
38+
ports:
39+
- 7001:7000
40+
- 9043:9042
41+
environment:
42+
- CASSANDRA_CLUSTER_NAME=cassandra-cluster
43+
- CASSANDRA_SEEDS=cassandra-node1,cassandra-node2,cassandra-node3
44+
- CASSANDRA_PASSWORD=cassandra
45+
46+
cassandra-node3:
47+
image: bitnami/cassandra:3
48+
volumes:
49+
- ./tmp/cassandra-node3:/bitnami
50+
ports:
51+
- 7003:7000
52+
- 9044:9042
53+
environment:
54+
- CASSANDRA_CLUSTER_NAME=cassandra-cluster
55+
- CASSANDRA_SEEDS=cassandra-node1,cassandra-node2,cassandra-node3
56+
- CASSANDRA_PASSWORD=cassandra

.docker/gateway/Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM nginx:alpine
2+
3+
RUN set -xe \
4+
&& apk update && apk upgrade \
5+
&& apk add --no-cache --update \
6+
bash \
7+
iproute2 \
8+
iptables \
9+
iputils\
10+
bind-tools \
11+
net-tools \
12+
iperf \
13+
tcpdump \
14+
nmap \
15+
netcat-openbsd \
16+
procps \
17+
&& rm -rf /var/cache/apk/* /tmp/*

.docker/gateway/nginx.conf

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
events {
2+
3+
}
4+
5+
6+
http {
7+
error_log /etc/nginx/error_log.log warn;
8+
9+
log_format main '$remote_addr - $remote_user [$time_local] "$host$request_uri" '
10+
'$status $body_bytes_sent "$http_referer" '
11+
'"$http_user_agent" "$http_x_forwarded_for"';
12+
13+
14+
15+
server {
16+
listen 80;
17+
18+
server_name spin3;
19+
20+
location / {
21+
proxy_pass https://spin3.sos112.si;
22+
proxy_set_header Host spin3.sos112.si;
23+
proxy_set_header X-Real-IP $remote_addr;
24+
proxy_ssl_server_name on;
25+
proxy_buffering off;
26+
27+
fastcgi_read_timeout 2s;
28+
proxy_read_timeout 2s;
29+
proxy_connect_timeout 2s;
30+
proxy_send_timeout 3s;
31+
send_timeout 2s;
32+
}
33+
}
34+
35+
server {
36+
listen 81;
37+
38+
server_name radar3;
39+
40+
location / {
41+
proxy_pass https://radar.topapp.si/;
42+
proxy_set_header Host radar.topapp.si;
43+
proxy_set_header X-Real-IP $remote_addr;
44+
proxy_ssl_server_name on;
45+
proxy_buffering off;
46+
47+
fastcgi_read_timeout 2s;
48+
proxy_read_timeout 2s;
49+
proxy_connect_timeout 2s;
50+
proxy_send_timeout 3s;
51+
send_timeout 2s;
52+
}
53+
}
54+
55+
server {
56+
listen 83;
57+
58+
server_name prominfo;
59+
60+
location / {
61+
proxy_pass https://prominfo.projekti.si;
62+
proxy_set_header Host prominfo.projekti.si;
63+
proxy_set_header X-Real-IP $remote_addr;
64+
proxy_ssl_server_name on;
65+
proxy_buffering off;
66+
67+
fastcgi_read_timeout 2s;
68+
proxy_read_timeout 2s;
69+
proxy_connect_timeout 2s;
70+
proxy_send_timeout 3s;
71+
send_timeout 2s;
72+
}
73+
}
74+
75+
server {
76+
listen 84;
77+
78+
server_name prominfo;
79+
80+
location / {
81+
proxy_pass https://meteo.arso.gov.si;
82+
proxy_set_header Host meteo.arso.gov.si;
83+
proxy_set_header X-Real-IP $remote_addr;
84+
proxy_ssl_server_name on;
85+
proxy_buffering off;
86+
87+
fastcgi_read_timeout 2s;
88+
proxy_read_timeout 2s;
89+
proxy_connect_timeout 2s;
90+
proxy_send_timeout 3s;
91+
send_timeout 2s;
92+
}
93+
}
94+
}

.envrc

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export EVENTBAY_HOME=/Users/otobrglez/Projects/eventbay
2+
export RADAR_TOKEN=2A25F0BE957ACE44F1012D40B1805833265EA6E338F71E477E86350C78324CBD

.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
tmp/
2+
!tmp/.keep
3+
4+
.env.user
5+
6+
hacking/
7+
8+
*.class
9+
*.log
10+
11+
# sbt specific
12+
.cache/
13+
.history/
14+
.lib/
15+
dist/*
16+
target/
17+
lib_managed/
18+
src_managed/
19+
project/boot/
20+
project/plugins/project/
21+
22+
# Scala-IDE specific
23+
.scala_dependencies
24+
.worksheet
25+
.idea
26+

NOTES.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Notes
2+
3+
## Networking
4+
5+
- https://netbeez.net/blog/how-to-use-the-linux-traffic-control/
6+
- https://www.cs.unm.edu/~crandall/netsfall13/TCtutorial.pdf
7+
8+
<pre>
9+
tc qdisc add dev eth0 root netem delay 5000ms
10+
11+
tc qdisc add dev eth0 root netem loss 90%
12+
13+
tc qdisc del root dev eth0
14+
tc qdisc show dev eth0
15+
</pre>
16+
17+
## Akka Streams
18+
19+
- https://medium.com/wbaa/akka-http-client-meets-zio-810781827ec

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Code and examples from Akka with Scala talk
2+
3+
Talk was given on Backend Meetup Slovenia, June 2021.
4+
5+
These are the examples.
6+
7+
Let me know if you need any help,
8+
9+
Regards!
10+
11+
- [Oto Brglez](https://github.com/otobrglez)

bin/eventbay-dev.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
if [[ -z "${EVENTBAY_HOME}" ]]; then
5+
echo "EVENTBAY_HOME environment variable is not set!"
6+
exit 255
7+
fi
8+
9+
cd $EVENTBAY_HOME && docker compose \
10+
-f .docker/docker-compose.development.yml \
11+
--project-name eventbay \
12+
--project-directory . $@

build.sbt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Dependencies._
2+
3+
name := "eventbay"
4+
5+
version := "0.1"
6+
7+
scalaVersion := "2.13.6"
8+
9+
libraryDependencies ++= {
10+
akka ++ logging ++ tapir ++ circe
11+
}

project/Dependencies.scala

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import sbt._
2+
3+
object Dependencies {
4+
5+
type Version = String
6+
7+
object Versions {
8+
val Sttp: Version = "3.3.4"
9+
val ScalaTest: Version = "3.2.8"
10+
11+
val Cats: Version = "2.6.0"
12+
val CatsEffect: Version = "3.1.1"
13+
val Circe: Version = "0.12.3"
14+
val Doobie: Version = "1.0.0-M4" // "0.12.1"
15+
val LogbackClassic: Version = "1.2.3"
16+
val ScalaLogging: Version = "3.9.3"
17+
val FS2: Version = "3.0.0"
18+
val Akka: Version = "2.6.14"
19+
val AkkaHttp: Version = "10.2.4"
20+
val Tapir: Version = "0.18.0-M15"
21+
}
22+
23+
val sttp = Seq(
24+
"com.softwaremill.sttp.client3" %% "core" % Versions.Sttp,
25+
"com.softwaremill.sttp.client3" %% "circe" % Versions.Sttp
26+
)
27+
28+
val cats = Seq(
29+
"org.typelevel" %% "cats-core" % Versions.Cats,
30+
"org.typelevel" %% "cats-effect" % Versions.CatsEffect
31+
)
32+
33+
val circe = Seq(
34+
"io.circe" %% "circe-core",
35+
"io.circe" %% "circe-generic",
36+
"io.circe" %% "circe-parser"
37+
).map(_ % Versions.Circe)
38+
39+
val doobie = Seq(
40+
"org.tpolecat" %% "doobie-core" % Versions.Doobie,
41+
"org.xerial" % "sqlite-jdbc" % "3.34.0"
42+
43+
// "org.tpolecat" %% "doobie-specs2" % "0.12.1" % "test", // Specs2 support for typechecking statements.
44+
// "org.tpolecat" %% "doobie-scalatest" % "0.12.1" % "test" // ScalaTest support for typechecking statements.
45+
)
46+
47+
val logging = Seq(
48+
"ch.qos.logback" % "logback-classic" % Versions.LogbackClassic,
49+
"com.typesafe.scala-logging" %% "scala-logging" % Versions.ScalaLogging,
50+
"com.softwaremill.sttp.client3" %% "slf4j-backend" % Versions.Sttp
51+
)
52+
53+
val apacheCommons = Seq(
54+
"org.apache.commons" % "commons-math3" % "3.6.1"
55+
)
56+
57+
val fs2 = Seq(
58+
"co.fs2" %% "fs2-core",
59+
"co.fs2" %% "fs2-io",
60+
"co.fs2" %% "fs2-reactive-streams"
61+
).map(_ % Versions.FS2)
62+
63+
val scalaTest = Seq(
64+
"org.scalatest" %% "scalatest" % Versions.ScalaTest
65+
)
66+
67+
val akka = Seq(
68+
// Classic
69+
"com.typesafe.akka" %% "akka-actor" % Versions.Akka,
70+
"com.typesafe.akka" %% "akka-testkit" % Versions.Akka % Test,
71+
72+
// Typed
73+
"com.typesafe.akka" %% "akka-actor-typed" % Versions.Akka,
74+
"com.typesafe.akka" %% "akka-actor-testkit-typed" % Versions.Akka % Test,
75+
76+
// Http
77+
"com.typesafe.akka" %% "akka-stream" % Versions.Akka,
78+
"com.typesafe.akka" %% "akka-http" % Versions.AkkaHttp,
79+
"com.typesafe.akka" %% "akka-http-xml" % Versions.AkkaHttp,
80+
81+
// Persistance
82+
"com.typesafe.akka" %% "akka-persistence-cassandra" % "1.0.5",
83+
"com.typesafe.akka" %% "akka-persistence" % Versions.Akka,
84+
"com.typesafe.akka" %% "akka-persistence-query" % Versions.Akka,
85+
"com.typesafe.akka" %% "akka-cluster-tools" % Versions.Akka
86+
)
87+
88+
val tapir = Seq(
89+
"com.softwaremill.sttp.tapir" %% "tapir-core",
90+
"com.softwaremill.sttp.tapir" %% "tapir-akka-http-server",
91+
"com.softwaremill.sttp.tapir" %% "tapir-openapi-docs",
92+
"com.softwaremill.sttp.tapir" %% "tapir-openapi-circe-yaml",
93+
94+
"com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-akka-http",
95+
"com.softwaremill.sttp.tapir" %% "tapir-redoc-akka-http"
96+
).map(_ % Versions.Tapir)
97+
}

project/build.properties

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version = 1.5.3

project/plugins.sbt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.20")

requests/services.http

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### SPIN3
2+
GET http://127.0.0.1:7070/javno/assets/data/lokacija.json
3+
Accept: application/json
4+
5+
###

requests/vreme.http

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
GET http://localhost:80/api/item?id=99
2+
Accept: application/json
3+
4+
### Directly
5+
GET https://meteo.arso.gov.si/uploads/probase/www/observ/surface/text/sl/observationAms_LJUBL-ANA_BEZIGRAD_latest.xml
6+
7+
### Via proxy
8+
GET http://localhost:7074/uploads/probase/www/observ/surface/text/sl/observationAms_LJUBL-ANA_BEZIGRAD_latest.xml

sql/persistance.sql

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE KEYSPACE IF NOT EXISTS akka
2+
WITH REPLICATION = { 'class' : 'SimpleStrategy','replication_factor':1 };
3+
4+
CREATE KEYSPACE IF NOT EXISTS akka_snapshot
5+
WITH REPLICATION = { 'class' : 'SimpleStrategy','replication_factor':1 };

0 commit comments

Comments
 (0)