I have Spring Boot
service which is listener to Kafka
cluster with @KafkaListner
. Kafka
provides json
data to instruct my service on what need to do. I convert this configuration json
to pojo
upon receiving it. I want to share this pojo
across my classes
& methods
. I don't want to pass through intermediary classes which doesn't need to know it
So, i did it like this.
- Create empty
pojo
and save into spring container first. - Then, after receiving from
Kafka
, fetch empty pojo fromspring container
andset
its values - This way i can get it from anywhere in my service.
But, I find this mutable pojo is not thread-safe. I explored bean-scope and nothing seems to suit me.
Can you guys suggest how to make it thread safe? can provide example on using custom SimpleThreadScope
?
Can you suggest any design pattern which doesn't need to use spring bean
?
Aucun commentaire:
Enregistrer un commentaire