From e742551926a76c0c97a116bb3091b93961483c9c Mon Sep 17 00:00:00 2001 From: Anthony Britton <105213050+anthony-britton-moj@users.noreply.github.com> Date: Wed, 22 Nov 2023 11:29:22 +0000 Subject: [PATCH] response body emitter (#2724) * PI-1619 response body emitter * update streaming timeout --- projects/tier-to-delius/deploy/values-dev.yml | 2 +- projects/tier-to-delius/deploy/values-preprod.yml | 2 +- projects/tier-to-delius/deploy/values-prod.yml | 2 +- .../uk/gov/justice/digital/hmpps/controller/CrnEmitter.kt | 7 ++++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/projects/tier-to-delius/deploy/values-dev.yml b/projects/tier-to-delius/deploy/values-dev.yml index 55e8d13caf..94d719c635 100644 --- a/projects/tier-to-delius/deploy/values-dev.yml +++ b/projects/tier-to-delius/deploy/values-dev.yml @@ -11,7 +11,7 @@ generic-service: INTEGRATIONS_TIER_URL: https://hmpps-tier-dev.hmpps.service.justice.gov.uk SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer - CRN-STREAMING_TIMEOUT: 10800000 + CRN-STREAMING_TIMEOUT: "10800000" LOGGING_LEVEL_UK_GOV_DIGITAL_JUSTICE_HMPPS: DEBUG diff --git a/projects/tier-to-delius/deploy/values-preprod.yml b/projects/tier-to-delius/deploy/values-preprod.yml index a94e9091bf..c553d81736 100644 --- a/projects/tier-to-delius/deploy/values-preprod.yml +++ b/projects/tier-to-delius/deploy/values-preprod.yml @@ -11,7 +11,7 @@ generic-service: INTEGRATIONS_TIER_URL: https://hmpps-tier-preprod.hmpps.service.justice.gov.uk SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer - CRN-STREAMING_TIMEOUT: 21600000L + CRN-STREAMING_TIMEOUT: "21600000" generic-prometheus-alerts: businessHoursOnly: true \ No newline at end of file diff --git a/projects/tier-to-delius/deploy/values-prod.yml b/projects/tier-to-delius/deploy/values-prod.yml index 6a5325fd9a..138992b04e 100644 --- a/projects/tier-to-delius/deploy/values-prod.yml +++ b/projects/tier-to-delius/deploy/values-prod.yml @@ -8,4 +8,4 @@ generic-service: INTEGRATIONS_TIER_URL: https://hmpps-tier.hmpps.service.justice.gov.uk SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer - CRN-STREAMING_TIMEOUT: 21600000L \ No newline at end of file + CRN-STREAMING_TIMEOUT: "21600000" \ No newline at end of file diff --git a/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/CrnEmitter.kt b/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/CrnEmitter.kt index bef0646824..0d51ebe9cf 100644 --- a/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/CrnEmitter.kt +++ b/projects/tier-to-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/controller/CrnEmitter.kt @@ -1,11 +1,12 @@ package uk.gov.justice.digital.hmpps.controller import org.springframework.beans.factory.annotation.Value +import org.springframework.http.MediaType import org.springframework.stereotype.Controller import org.springframework.transaction.PlatformTransactionManager import org.springframework.transaction.support.TransactionTemplate import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.servlet.mvc.method.annotation.SseEmitter +import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter import uk.gov.justice.digital.hmpps.service.CrnStreamingService import java.util.concurrent.Executors @@ -18,11 +19,11 @@ class CrnEmitter( private val executorService = Executors.newSingleThreadExecutor() @GetMapping("/probation-cases") - fun handleSse(): SseEmitter = SseEmitter(timeout).also { emitter -> + fun handleSse(): ResponseBodyEmitter = ResponseBodyEmitter(timeout).also { emitter -> executorService.execute { TransactionTemplate(transactionManager).execute { crnStreamingService.getActiveCrns().use { stream -> - stream.forEach { emitter.send(it) } + stream.forEach { emitter.send(it + System.lineSeparator(), MediaType.TEXT_PLAIN) } emitter.complete() } }