Add booking SSE stream and emit on updates
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.android.trisolarisserver.component
|
||||
|
||||
import com.android.trisolarisserver.controller.BookingSnapshotBuilder
|
||||
import com.android.trisolarisserver.controller.dto.BookingDetailResponse
|
||||
import org.springframework.scheduling.annotation.Scheduled
|
||||
import org.springframework.stereotype.Component
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter
|
||||
import java.util.UUID
|
||||
|
||||
@Component
|
||||
class BookingEvents(
|
||||
private val bookingSnapshotBuilder: BookingSnapshotBuilder
|
||||
) {
|
||||
private val hub = SseHub<BookingKey>("booking") { key ->
|
||||
bookingSnapshotBuilder.build(key.propertyId, key.bookingId)
|
||||
}
|
||||
|
||||
fun subscribe(propertyId: UUID, bookingId: UUID): SseEmitter {
|
||||
return hub.subscribe(BookingKey(propertyId, bookingId))
|
||||
}
|
||||
|
||||
fun emit(propertyId: UUID, bookingId: UUID) {
|
||||
hub.emit(BookingKey(propertyId, bookingId))
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelayString = "25000")
|
||||
fun heartbeat() {
|
||||
hub.heartbeat()
|
||||
}
|
||||
}
|
||||
|
||||
private data class BookingKey(
|
||||
val propertyId: UUID,
|
||||
val bookingId: UUID
|
||||
)
|
||||
Reference in New Issue
Block a user