Hi have implemented producer and consumer in my existing spring boot application.
Producer sending message properly to topic and even consumer also listening consuming message from topic. Here producer used with StreamBridge
, it called from rest endpoint from the controller.
In the consumer afte it taking message i am making a internal service call it has httpclient realted and RequestContextHolder related calls.
my consumer looks like below
Consumer<Message<String>> input(){
return str - > {
log(str);
validateservice.validatData(str);
};}
my validateData methods looks as below
validateData ()
{
.....
RequestContextHolder.currentRequestAttributes().setAttribute("text", document, RequestAttributes.SCOPE_REQUEST);
....
}
at the above line RequestContextHolder.currentRequestAttributes()
... i am getting below error
14:28:44.747 [KafkaConsumerDestination{consumerDestinationName='xyz', partitions=0, dlqName='null'}.container-0-C-1] ERROR c.c.v.f.d.s.ValidateData - Error preparing external data
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
at com.dfd.vsg.fnc.utils.CustomJAXBConvert.readFromSource(CustomJAXBConvert.java:174)
I have gone through How to enable request scope in async task executor and tried all the solutions, its not working.
Updated Question :
actually validatData is used in controller only, as there are few calls want make few async, so in that process first call will send message to topic and wont look for response. and the message will by consumer and send it to the validatData() method