简体   繁体   中英

reactivex and REST Web services

I have a situation where an application has a list of values, for example, a list of books, that changes from time to time. It also has a REST endpoint where this information is published.

There are several other applications that consume this information, and they should be aware if any of the books on my application changes.

Would the reactive style be adequate to this situation? At first, I thought so, based on the Observer pattern. But would this be a good approach, considering the applications involved only exchange information based on web services?

I also looked at retrofit, that could transform the endpoints, into java interfaces. But all the examples I found, were somehow related to android applications.

So, would this approach be advisable in this scenario? If it is, can someone recommend a book, or any kind of resource?

EDIT:

Since I will have an endpoint that publishes books, should I turn it in to an Observable, that when gets another book available, notifies all the subscribers of this event, and that would in turn decide if they should or not do something? If so, how would a client, it can be for example, and angularjs app or another java application, subscribe to this observable?

I hope I could make myself a little bit more clear.

I think you are mixing up the Rx programming with a network problem. If your server sends data over the network at X interval of time then as @TheCoder said you can listen for changes on a socket and trigger an event on your rx stream with the help of a PublishSubject . But I think that the real issue lies in the way your data are sent by your server.

If you have to query your server to know if your list of books has been updated it is not very effective to trigger such calls when your goal is to have a real time update. In these type of scenario a Publish-Subscribe pattern is more appropriated where your client just act a receiver and can update itself as soon as your server push new values (a new list of book in your case). You can find tools like pubnub or the MQTT protocol to achieve such things.

For you to understand quickly how this system works you can look at this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM