Skip to content

Commit

Permalink
response body emitter (#2724)
Browse files Browse the repository at this point in the history
* PI-1619 response body emitter

* update streaming timeout
  • Loading branch information
anthony-britton-moj authored Nov 22, 2023
1 parent c4d2702 commit e742551
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion projects/tier-to-delius/deploy/values-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion projects/tier-to-delius/deploy/values-preprod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion projects/tier-to-delius/deploy/values-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
CRN-STREAMING_TIMEOUT: "21600000"
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()
}
}
Expand Down

0 comments on commit e742551

Please sign in to comment.