File tree Expand file tree Collapse file tree
sentry-samples/sentry-samples-spring-boot-jakarta
java/io/sentry/samples/spring/boot/jakarta Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -183,6 +183,7 @@ springboot3-starter-security = { module = "org.springframework.boot:spring-boot-
183183springboot3-starter-jdbc = { module = " org.springframework.boot:spring-boot-starter-jdbc" , version.ref = " springboot3" }
184184springboot3-starter-actuator = { module = " org.springframework.boot:spring-boot-starter-actuator" , version.ref = " springboot3" }
185185springboot3-starter-cache = { module = " org.springframework.boot:spring-boot-starter-cache" , version.ref = " springboot3" }
186+ spring-kafka3 = { module = " org.springframework.kafka:spring-kafka" , version = " 3.3.5" }
186187springboot4-otel = { module = " io.opentelemetry.instrumentation:opentelemetry-spring-boot-starter" , version.ref = " otelInstrumentation" }
187188springboot4-resttestclient = { module = " org.springframework.boot:spring-boot-resttestclient" , version.ref = " springboot4" }
188189springboot4-starter = { module = " org.springframework.boot:spring-boot-starter" , version.ref = " springboot4" }
Original file line number Diff line number Diff line change @@ -59,6 +59,9 @@ dependencies {
5959 implementation(libs.springboot3.starter.cache)
6060 implementation(libs.caffeine)
6161
62+ // kafka
63+ implementation(libs.spring.kafka3)
64+
6265 // OpenFeature SDK
6366 implementation(libs.openfeature)
6467
Original file line number Diff line number Diff line change 1+ package io .sentry .samples .spring .boot .jakarta ;
2+
3+ import org .slf4j .Logger ;
4+ import org .slf4j .LoggerFactory ;
5+ import org .springframework .context .annotation .Profile ;
6+ import org .springframework .kafka .annotation .KafkaListener ;
7+ import org .springframework .stereotype .Component ;
8+
9+ @ Component
10+ @ Profile ("kafka" )
11+ public class KafkaConsumer {
12+
13+ private static final Logger logger = LoggerFactory .getLogger (KafkaConsumer .class );
14+
15+ @ KafkaListener (topics = "sentry-topic" , groupId = "sentry-sample-group" )
16+ public void listen (String message ) {
17+ logger .info ("Received message: {}" , message );
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ package io .sentry .samples .spring .boot .jakarta ;
2+
3+ import org .springframework .context .annotation .Profile ;
4+ import org .springframework .kafka .core .KafkaTemplate ;
5+ import org .springframework .web .bind .annotation .GetMapping ;
6+ import org .springframework .web .bind .annotation .RequestMapping ;
7+ import org .springframework .web .bind .annotation .RequestParam ;
8+ import org .springframework .web .bind .annotation .RestController ;
9+
10+ @ RestController
11+ @ Profile ("kafka" )
12+ @ RequestMapping ("/kafka" )
13+ public class KafkaController {
14+
15+ private final KafkaTemplate <String , String > kafkaTemplate ;
16+
17+ public KafkaController (KafkaTemplate <String , String > kafkaTemplate ) {
18+ this .kafkaTemplate = kafkaTemplate ;
19+ }
20+
21+ @ GetMapping ("/produce" )
22+ String produce (@ RequestParam (defaultValue = "hello from sentry!" ) String message ) {
23+ kafkaTemplate .send ("sentry-topic" , message );
24+ return "Message sent: " + message ;
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ # Kafka — activate with: --spring.profiles.active=kafka
2+ spring.autoconfigure.exclude =
3+ spring.kafka.bootstrap-servers =localhost:9092
4+ spring.kafka.consumer.group-id =sentry-sample-group
5+ spring.kafka.consumer.auto-offset-reset =earliest
6+ spring.kafka.consumer.key-deserializer =org.apache.kafka.common.serialization.StringDeserializer
7+ spring.kafka.consumer.value-deserializer =org.apache.kafka.common.serialization.StringDeserializer
8+ spring.kafka.producer.key-serializer =org.apache.kafka.common.serialization.StringSerializer
9+ spring.kafka.producer.value-serializer =org.apache.kafka.common.serialization.StringSerializer
Original file line number Diff line number Diff line change @@ -37,6 +37,10 @@ spring.quartz.job-store-type=memory
3737
3838# Cache tracing
3939sentry.enable-cache-tracing =true
40+
41+ # Kafka is only active with the 'kafka' profile (--spring.profiles.active=kafka)
42+ spring.autoconfigure.exclude =org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration
43+
4044spring.cache.cache-names =todos
4145spring.cache.caffeine.spec =maximumSize=500,expireAfterAccess=600s
4246
You can’t perform that action at this time.
0 commit comments