|
5 | 5 | */ |
6 | 6 | package org.tailormap.api.configuration; |
7 | 7 |
|
| 8 | +import ch.rasc.sse.eventbus.DataObjectConverter; |
| 9 | +import ch.rasc.sse.eventbus.DefaultDataObjectConverter; |
| 10 | +import ch.rasc.sse.eventbus.DefaultSubscriptionRegistry; |
| 11 | +import ch.rasc.sse.eventbus.DistributedEventBus; |
| 12 | +import ch.rasc.sse.eventbus.JacksonDataObjectConverter; |
| 13 | +import ch.rasc.sse.eventbus.ReplayStore; |
| 14 | +import ch.rasc.sse.eventbus.SseEventBus; |
| 15 | +import ch.rasc.sse.eventbus.SubscriptionRegistry; |
8 | 16 | import ch.rasc.sse.eventbus.config.EnableSseEventBus; |
| 17 | +import ch.rasc.sse.eventbus.config.SseEventBusConfigurer; |
| 18 | +import ch.rasc.sse.eventbus.observation.SseEventBusObservationConvention; |
| 19 | +import io.micrometer.observation.ObservationRegistry; |
| 20 | +import java.util.ArrayList; |
| 21 | +import java.util.List; |
9 | 22 | import java.util.Locale; |
| 23 | +import org.jspecify.annotations.Nullable; |
| 24 | +import org.springframework.beans.factory.annotation.Autowired; |
10 | 25 | import org.springframework.beans.factory.annotation.Value; |
11 | 26 | import org.springframework.boot.context.properties.ConfigurationProperties; |
12 | 27 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|
15 | 30 | import org.springframework.scheduling.annotation.EnableScheduling; |
16 | 31 | import org.springframework.web.servlet.LocaleResolver; |
17 | 32 | import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; |
| 33 | +import tools.jackson.databind.ObjectMapper; |
18 | 34 |
|
19 | 35 | @Configuration |
20 | 36 | @EnableConfigurationProperties |
@@ -42,4 +58,39 @@ public LocaleResolver localeResolver() { |
42 | 58 | resolver.setDefaultLocale(Locale.of(defaultLanguage)); |
43 | 59 | return resolver; |
44 | 60 | } |
| 61 | + |
| 62 | + // New viewer SseEventBus bean for viewer-specific SSE traffic. |
| 63 | + @Bean("viewerSseEventBus") |
| 64 | + public SseEventBus viewerSseEventBus( |
| 65 | + @Autowired(required = false) @Nullable SseEventBusConfigurer configurer, |
| 66 | + @Autowired(required = false) @Nullable ObjectMapper objectMapper, |
| 67 | + @Autowired(required = false) @Nullable List<DataObjectConverter> dataObjectConverters, |
| 68 | + @Autowired(required = false) @Nullable SubscriptionRegistry subscriptionRegistry, |
| 69 | + @Autowired(required = false) @Nullable ReplayStore replayStore, |
| 70 | + @Autowired(required = false) @Nullable ObservationRegistry observationRegistry, |
| 71 | + @Autowired(required = false) @Nullable SseEventBusObservationConvention observationConvention, |
| 72 | + @Autowired(required = false) @Nullable DistributedEventBus distributedEventBus) { |
| 73 | + |
| 74 | + // Apply same defaults as DefaultSseEventBusConfiguration |
| 75 | + SseEventBusConfigurer config = configurer != null |
| 76 | + ? configurer |
| 77 | + : new SseEventBusConfigurer() { |
| 78 | + /* defaults */ |
| 79 | + }; |
| 80 | + |
| 81 | + SubscriptionRegistry registry = |
| 82 | + subscriptionRegistry != null ? subscriptionRegistry : new DefaultSubscriptionRegistry(); |
| 83 | + |
| 84 | + ReplayStore store = replayStore != null ? replayStore : config.replayStore(); |
| 85 | + |
| 86 | + List<DataObjectConverter> converters = dataObjectConverters != null ? dataObjectConverters : new ArrayList<>(); |
| 87 | + if (objectMapper != null) { |
| 88 | + converters.add(new JacksonDataObjectConverter(objectMapper)); |
| 89 | + } else { |
| 90 | + converters.add(new DefaultDataObjectConverter()); |
| 91 | + } |
| 92 | + |
| 93 | + return new SseEventBus( |
| 94 | + config, registry, converters, store, observationRegistry, observationConvention, distributedEventBus); |
| 95 | + } |
45 | 96 | } |
0 commit comments