Sandymcp
08/15/2023, 1:30 PMclass EngineSseConsumer(
private val engineClient: ApplicationClient,
private val forwardAuth: ForwardAuthorization,
private val consumers: List<Consumer<Event>>,
) : SseConsumer {
override fun invoke(sse: Sse) {
val auth = forwardAuth.forward(sse.connectRequest)
engineClient.notifications(-1, auth).forEach { n ->
consumers.forEach { it.accept(Event(n, auth)) }
}
}
The function forwardAuth.forward
is stripping the Bearer token out of the incoming request and wrapping it so it can be forwarded to a backend service.
The routing looks like this
fun sseRoutes(
engineClient: ApplicationClient,
forwardAuth: ForwardAuthorization,
): RoutingSseHandler =
sse(
"/iou/sse" bind EngineSseConsumer(
engineClient,
forwardAuth,
listOf(
IouCompleteEventConsumer(engineClient),
PaymentEventConsumer(engineClient),
),
),
)
I can always recreate the previous situation by extending the interface, but I'm sure there's a better way, perhaps with the use of a filter, but I'm having trouble getting my head around that.dave
08/15/2023, 1:51 PMdave
08/15/2023, 1:51 PMSandymcp
08/15/2023, 1:52 PMdave
08/15/2023, 1:54 PMAndrew O'Hara
08/15/2023, 2:01 PMdave
08/15/2023, 2:02 PM