reactive-programming

Is there a way to subscribe an observer as async

我怕爱的太早我们不能终老 提交于 2019-12-30 07:39:27
问题 Given a synchronous observer, is there a way to do this: observable.SubscribeAsync(observer); And have all methods on the observer called asynchronously or is that something I have to handle when creating the observer? 回答1: You might want to look into ObserveOn and SubscribeOn (more information and even more information). 回答2: If you need to call an async method when the stream spits out a new value, the most common solution you will find is to use SelectMany . The problem is that this doesn

Make Http call using ReactiveX for Java

若如初见. 提交于 2019-12-30 06:16:08
问题 I am new to ReactiveX for Java and I've the following code block that make external http call but it is not async. We are using rxjava 1.2, and Java 1.8 private ResponseEntity<String> callExternalUrl(String url, String json, HttpMethod method) { RestTemplate restTemplate; HttpEntity request; request = new HttpEntity(jsonContent, httpHeaders); return restTemplate.exchange(url, httpMethod, request, String.class); } I've the following code block I found online but I couldn't totally understand

Reactive WebClient not emitting a response

时光怂恿深爱的人放手 提交于 2019-12-29 06:51:49
问题 I have a question about Spring Reactive WebClient... Few days ago I decided to play with the new reactive stuff in Spring Framework and I made one small project for scraping data only for personal purposes. (making multiple requests to one webpage and combining the results). I started using the new reactive WebClient for making requests but the problem I found is that the client not emitting response for every request. Sounds strange. Here is what I did for fetching data: private Mono<String>

How to get String from Mono<String> in reactive java

可紊 提交于 2019-12-29 05:25:48
问题 I have a method which accepts Mono as a param. All I want is to get the actual String from it. Googled but didn't find answer except calling block() over Mono object but it will make a blocking call so want to avoid using block(). Please suggest other way if possible. The reason why I need this String is because inside this method I need to call another method say print() with the actual String value. I understand this is easy but I am new to reactive programming. Code: public String getValue

How to handle exceptions thrown by observer's onNext in RxJava?

爱⌒轻易说出口 提交于 2019-12-28 11:59:18
问题 Consider the following example: Observable.range(1, 10).subscribe(i -> { System.out.println(i); if (i == 5) { throw new RuntimeException("oops!"); } }, Throwable::printStackTrace); This outputs numbers from 1 to 5 and then prints the exception. What I want to achieve is make the observer stay subscribed and continue to run after throwing an exception, i.e. print all numbers from 1 to 10. I have tried using retry() and other various error handling operators, but, as said in the documentation,

RxJava - Merged Observable that accepts more Observables at any time?

偶尔善良 提交于 2019-12-25 08:08:46
问题 I am encountering a need for an Observable implementation that holds one or more Observables and merges them. But here is the kicker: I want to add more Observables to be merged at any time, and I guess it might as well support removing them too. For it to be truly effective, all Subscribers must receive notifications from new Observables that are added post-subscription. Unless all the merged Observables are cold and call onComplete() , then I guess it is okay to let the subscriptions

Building a Sensor Monitoring System using RX

偶尔善良 提交于 2019-12-25 07:13:00
问题 See Merging multiple custom observables in RX for background. My scenario is that I have a number of arbitrary sensors (hardware). I have written some pluggable modules that can connect to these sensors in C#. They currently each use a thread to run an acquisition routine on a timer. The larger goal is to change polling to RX as well once I understand how! There is a requirement to monitor these sensors in groups so I was thinking there would be an aggregated topic where a monitor could

Nested observeEvent() in observer() gets executed too often

心已入冬 提交于 2019-12-25 07:12:01
问题 My code looks like observe ({ #subset someDataframe which I need in the observeEvent() observeEvent(input$Numbers{ #if not NULL, do something with subsetted dataframe }) }) I have an observe() function which gets input from the ui.R . Depending on the input, I subset a dataframe which will be displayed in the app. There is the need for further subsetting, but this field can be empty. To avoid the Unhandled Error if the selection is empty (thus, NULL ) is use the observeEvent() function. If

Play-Framework 2.3.x: Unable to send emails using plugin “play-mailer”

非 Y 不嫁゛ 提交于 2019-12-25 06:13:07
问题 I am using play-framework 2.3.x and scala 2.11.4 . When integrate play-mailer for sending and emails from my application, there is nothing happen. In the logs there are no exception produces and no return values are available. Following is email properties: smtp.host = "smtp.gmail.com" smtp.port = 25 smtp.user = "n****@gmail.com" smtp.password = "*******" smtp.debug = true smtp.mock = true My Scala Code: Future{ var subject = "Invitation email"; var from = "h****@gmail.com"; var to = userList

Windows Service just stops. No messages, no alerts, errors, warning - nothing

与世无争的帅哥 提交于 2019-12-25 05:14:20
问题 I have a Windows service that just silently stops on its own. Here is the relevant code: OnStart() method: protected override void OnStart(string[] args) { try { InitializeLogging(); // we don't DO command line arguments if (args.Length > 0) { eventLog.WriteEntry("All command line arguments are ignored. You must edit the app.config file manually to make changes to what watchers are run."); throw new ArgumentException("Command line arguments are ignored."); } ReadAppConfig();