0

I have a mono content out of this i need to get the data to variable.

private String name;
 var result = Mono.just("surendra")
      
      .subscribe(x -> name=x);

  LOG.info("Hello " + name);

Tried the above code to get the value but it is showing as null.

Can you please help me the way i can get the content from Mono with non blocking way Thanks in Advance:)

  • Why not `subscribe(x -> LOG.info("Hello " + x))`? (Also note that you should normally not use string pasting in logs; there are template features in most loggers that are better and faster.) – chrylis -cautiouslyoptimistic- Apr 29 '21 at 15:46
  • 2
    You cannot achieve what you're trying to do. Part of reactive programming is thinking also in functional programming way. So your code should avoid mutations like the one in the lambda argument passed to `subscribe` method. – Luiggi Mendoza Apr 29 '21 at 15:48
  • you fundamentally can't get something out of a Mono unless you block. It would be best if you explained what it is you are trying to achieve instead. – Toerktumlare Apr 29 '21 at 16:47
  • @Toerktumlare Thanks for the response !! In my implementation I need to proceed further with that value , Getting that mono content from external API , but unable to extract that use it further, please suggest any other alternatives – Surendra Batreddy May 02 '21 at 17:00
  • @chrylis-cautiouslyoptimistic- Thanks for the response !! I used the same syntax for logging , its printing over the logs , But i need to proceed further based on that string value on my implementation , Please Suggest – Surendra Batreddy May 02 '21 at 17:01
  • without exact further details, i suggest you read up on the basics of reactive programming, so you actually understand what it is you are asking. there is nothing we can do to help you. This question has been closed. – Toerktumlare May 02 '21 at 23:45

0 Answers0