/notifications-engine

Notifications Engine

Primary LanguageScalaApache License 2.0Apache-2.0

Notifications Engine

GitHub Workflow Status Scala Steward badge Mergify Status

This is an adaptation of the blog entry Building High-Performance Notification Engine Using Pure Functional Scala, ZIO HTTP, ZIO Kafka. Event-Driven Architecture (by Oluwaseyi Otun) to the following stack:

  • Cats Effect: Is an asynchronous runtime for Scala.
  • FS2 Kafka: Provides Apache Kafka Streams for Scala.
  • Vulcan: Provides Apache Avro data serialization for Scala.
  • http4s: HTTP servers and clients for Scala.
  • MUnit: Is a Scala testing library.

Examples

curl --url http://localhost:8080/api/v1/email \
     --header 'content-type: application/json' \
     --data '{"body":"Hello","subject":"Greetings from Mary","from":{"user":"Mary"},"to":{"user":"Rose"}}' 
curl --url http://localhost:8080/api/v1/sms \
     --header 'content-type: application/json' \
     --data '{"body":"Hi!","from":{"user":"John"},"to":{"user":"Jane"}}' 
curl --url http://localhost:8080/api/v1/webhook \
     --header 'content-type: application/json' \
     --data '{"body":"Have a nice day!","host":"www.example.org","port":"8080","hookUrl":"http://example.org/hook"}'

Build binary packages

sbt "project notifications-gateway" Universal/packageBin
sbt "project notifications-dispatcher" Universal/packageBin

Schema

curl -s http://localhost:8081/subjects | jq
[
  "notifications-engine-tests-key",
  "notifications-engine-tests-value"
]
curl -s http://localhost:8081/subjects/notifications-engine-tests-key/versions/latest | jq
{
  "subject": "notifications-engine-tests-key",
  "version": 1,
  "id": 1,
  "schema": "\"string\""
}
curl -s http://localhost:8081/subjects/notifications-engine-tests-value/versions/latest | jq
{
  "subject": "notifications-engine-tests-value",
  "version": 1,
  "id": 2,
  "schema": "[{\"type\":\"record\",\"name\":\"EmailSent\",\"namespace\":\"es.eriktorr.notifications_engine\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"emailMessage\",\"type\":{\"type\":\"record\",\"name\":\"EmailMessage\",\"fields\":[{\"name\":\"body\",\"type\":\"string\"},{\"name\":\"subject\",\"type\":\"string\"},{\"name\":\"from\",\"type\":\"string\"},{\"name\":\"to\",\"type\":\"string\"}]}}]},{\"type\":\"record\",\"name\":\"SmsSent\",\"namespace\":\"es.eriktorr.notifications_engine\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"smsMessage\",\"type\":{\"type\":\"record\",\"name\":\"SmsMessage\",\"fields\":[{\"name\":\"body\",\"type\":\"string\"},{\"name\":\"from\",\"type\":\"string\"},{\"name\":\"to\",\"type\":\"string\"}]}}]},{\"type\":\"record\",\"name\":\"WebhookSent\",\"namespace\":\"es.eriktorr.notifications_engine\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"webhookMessage\",\"type\":{\"type\":\"record\",\"name\":\"WebhookMessage\",\"fields\":[{\"name\":\"body\",\"type\":\"string\"},{\"name\":\"host\",\"type\":\"string\"},{\"name\":\"port\",\"type\":\"int\"},{\"name\":\"hookUrl\",\"type\":\"string\"}]}}]}]"
curl -s http://localhost:8081/subjects/notifications-engine-tests-value/versions
[1]

See also