Skip to content

Commit 8310ebe

Browse files
committed
add support for websocket notifications
1 parent 60552d7 commit 8310ebe

File tree

30 files changed

+403
-41
lines changed

30 files changed

+403
-41
lines changed

api/src/main/scala/app/softnetwork/notification/api/AllNotificationsApi.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package app.softnetwork.notification.api
22

33
import akka.actor.typed.ActorSystem
44
import app.softnetwork.notification.handlers.AllNotificationsHandler
5-
import app.softnetwork.notification.launch.NotificationApplication
5+
import app.softnetwork.notification.launch.{NotificationApplication, NotificationRoutes}
66
import app.softnetwork.notification.model.Notification
77
import app.softnetwork.notification.persistence.query.{
88
NotificationCommandProcessorStream,
@@ -17,7 +17,9 @@ import app.softnetwork.persistence.schema.SchemaProvider
1717
import app.softnetwork.scheduler.config.SchedulerSettings
1818
import com.typesafe.config.Config
1919

20-
trait AllNotificationsApi extends NotificationApplication[Notification] { _: SchemaProvider =>
20+
trait AllNotificationsApi
21+
extends NotificationApplication[Notification]
22+
with NotificationRoutes[Notification] { _: SchemaProvider =>
2123

2224
override def notificationBehaviors: ActorSystem[_] => Seq[NotificationBehavior[Notification]] =
2325
_ => Seq(AllNotificationsBehavior)

api/src/main/scala/app/softnetwork/notification/api/AllNotificationsPostgresLauncher.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@ object AllNotificationsPostgresLauncher extends AllNotificationsApi with JdbcSch
1212

1313
override def schemaType: SchemaType = JdbcSchemaTypes.Postgres
1414

15-
override def apiRoutes: ActorSystem[_] => List[ApiRoute] = _ => List.empty
16-
1715
}

build.sbt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ThisBuild / organization := "app.softnetwork"
22

33
name := "notification"
44

5-
ThisBuild / version := "0.7.0"
5+
ThisBuild / version := "0.8.0-SNAPSHOT"
66

77
ThisBuild / scalaVersion := "2.12.18"
88

@@ -24,7 +24,9 @@ val scalatest = Seq(
2424

2525
ThisBuild / libraryDependencies ++= Seq(
2626
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf",
27-
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.1"
27+
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.1",
28+
"org.apache.commons" % "commons-lang3" % "3.15.0",
29+
"org.slf4j" % "slf4j-api" % Versions.slf4j,
2830
) ++ scalatest
2931

3032
Test / parallelExecution := false

common/build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ libraryDependencies ++= Seq(
1818
ExclusionRule(organization = "com.google.auth", name = "google-auth-library-oauth2-http")
1919
/*, ExclusionRule(organization = "org.apache.commons", name = "commons-lang3")*/,
2020
ExclusionRule(organization = "io.netty"),
21-
ExclusionRule(organization = "io.grpc")
21+
ExclusionRule(organization = "io.grpc"),
22+
ExclusionRule(organization = "org.slf4j"),
2223
),
2324
"com.eatthepath" % "pushy" % "0.15.1"
2425
)

common/src/main/protobuf/api/notification.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ service NotificationServiceApi {
1414
rpc AddMail (AddMailRequest) returns (AddNotificationResponse) {}
1515
rpc AddSMS (AddSMSRequest) returns (AddNotificationResponse) {}
1616
rpc AddPush (AddPushRequest) returns (AddNotificationResponse) {}
17+
rpc AddWs (AddWsRequest) returns (AddNotificationResponse) {}
1718
rpc RemoveNotification (RemoveNotificationRequest) returns (RemoveNotificationResponse) {}
1819
rpc SendMail (SendMailRequest) returns (SendNotificationResponse) {}
1920
rpc SendSMS (SendSMSRequest) returns (SendNotificationResponse) {}
2021
rpc SendPush (SendPushRequest) returns (SendNotificationResponse) {}
22+
rpc SendWs (SendWsRequest) returns (SendNotificationResponse) {}
2123
rpc GetNotificationStatus (GetNotificationStatusRequest) returns (GetNotificationStatusResponse) {}
2224
}
2325

@@ -33,6 +35,10 @@ message AddPushRequest{
3335
app.softnetwork.notification.model.Push push = 1;
3436
}
3537

38+
message AddWsRequest{
39+
app.softnetwork.notification.model.Ws ws = 1;
40+
}
41+
3642
message AddNotificationResponse{
3743
bool succeeded = 1;
3844
}
@@ -57,6 +63,10 @@ message SendPushRequest{
5763
app.softnetwork.notification.model.Push push = 1;
5864
}
5965

66+
message SendWsRequest{
67+
app.softnetwork.notification.model.Ws ws = 1;
68+
}
69+
6070
message SendNotificationResponse{
6171
repeated app.softnetwork.notification.model.NotificationStatusResult results = 1;
6272
}

common/src/main/protobuf/message/notification.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ message NotificationRecordedEvent {
2727
app.softnetwork.notification.model.Mail mail = 1;
2828
app.softnetwork.notification.model.SMS sms = 2;
2929
app.softnetwork.notification.model.Push push = 3;
30+
app.softnetwork.notification.model.Ws ws = 4;
3031
}
3132
}
3233

@@ -45,6 +46,7 @@ message ExternalEntityToNotificationEvent{
4546
app.softnetwork.notification.message.AddSMSCommandEvent addSMS = 2;
4647
app.softnetwork.notification.message.AddPushCommandEvent addPush = 3;
4748
app.softnetwork.notification.message.RemoveNotificationCommandEvent removeNotification = 4;
49+
app.softnetwork.notification.message.AddWsCommandEvent addWs = 5;
4850
}
4951
}
5052

@@ -66,6 +68,12 @@ message AddPushCommandEvent{
6668
required app.softnetwork.notification.model.Push notification = 1;
6769
}
6870

71+
message AddWsCommandEvent{
72+
option (scalapb.message).extends = "ProtobufEvent";
73+
option (scalapb.message).extends = "AddNotificationCommandEvent";
74+
required app.softnetwork.notification.model.Ws notification = 1;
75+
}
76+
6977
message RemoveNotificationCommandEvent{
7078
option (scalapb.message).extends = "ProtobufEvent";
7179
option (scalapb.message).extends = "ExternalNotificationEvent";

common/src/main/protobuf/model/notificationType.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ enum NotificationType {
1414
MAIL_TYPE = 1;
1515
SMS_TYPE = 2;
1616
PUSH_TYPE = 3;
17+
WS_TYPE = 4;
1718
}

common/src/main/protobuf/model/notifications.proto

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,25 @@ message Push{
138138
optional string application = 24;
139139
}
140140

141+
message Ws{
142+
option (scalapb.message).extends = "ProtobufDomainObject";
143+
option (scalapb.message).extends = "Notification";
144+
required string uuid = 1;
145+
required google.protobuf.Timestamp createdDate = 2 [(scalapb.field).type = "java.time.Instant"];
146+
required google.protobuf.Timestamp lastUpdated = 3 [(scalapb.field).type = "java.time.Instant"];
147+
required From from = 4;
148+
repeated string to = 5;
149+
required string subject = 8;
150+
required string message = 9;
151+
required int32 maxTries = 13 [default = 1];
152+
required int32 nbTries = 14 [default = 0];
153+
optional google.protobuf.Timestamp deferred = 15 [(scalapb.field).type = "java.time.Instant"];
154+
optional string ackUuid = 16;
155+
required NotificationStatus status = 17 [default = Pending];
156+
repeated NotificationStatusResult results = 18;
157+
required NotificationType type = 19 [default = WS_TYPE];
158+
}
159+
141160
message PushPayload{
142161
option (scalapb.message).extends = "ProtobufDomainObject";
143162
required string application = 1;

common/src/main/resources/reference.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ notification {
44
event-streams {
55
external-to-notification-tag = "external-to-notification"
66
}
7+
8+
path = "notification"
79
}

common/src/main/scala/app/softnetwork/notification/api/NotificationClient.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package app.softnetwork.notification.api
33
import akka.actor.typed.ActorSystem
44
import akka.grpc.GrpcClientSettings
55
import app.softnetwork.api.server.client.{GrpcClient, GrpcClientFactory}
6-
import app.softnetwork.notification.model.{Mail, NotificationStatusResult, Push, SMS}
6+
import app.softnetwork.notification.model.{Mail, NotificationStatusResult, Push, SMS, Ws}
77

88
import scala.concurrent.Future
99

@@ -26,6 +26,10 @@ trait NotificationClient extends GrpcClient {
2626
grpcClient.addPush(AddPushRequest(Some(push))) map (_.succeeded)
2727
}
2828

29+
def addWs(ws: Ws): Future[Boolean] = {
30+
grpcClient.addWs(AddWsRequest(Some(ws))) map (_.succeeded)
31+
}
32+
2933
def removeNotification(uuid: String): Future[Boolean] = {
3034
grpcClient.removeNotification(RemoveNotificationRequest(uuid)) map (_.succeeded)
3135
}
@@ -42,6 +46,10 @@ trait NotificationClient extends GrpcClient {
4246
grpcClient.sendPush(SendPushRequest(Some(push))) map (_.results)
4347
}
4448

49+
def sendWs(ws: Ws): Future[Seq[NotificationStatusResult]] = {
50+
grpcClient.sendWs(SendWsRequest(Some(ws))) map (_.results)
51+
}
52+
4553
def getNotificationStatus(uuid: String): Future[Seq[NotificationStatusResult]] = {
4654
grpcClient.getNotificationStatus(GetNotificationStatusRequest(uuid)) map (_.results)
4755
}

0 commit comments

Comments
 (0)