I'm studying reactive streams concepts. I understand it's non-blocking processing of demand-driven, push-based data streams.
The central concept is backpressure, which means the consumer controls the flow of data from upstream producer.
How is the backpressure implemented at service boundary? Let's say I have web service which returns large collection of data. Clients should be able to stream the return payload. How to make the service reactive in this context? Is it possible to define reactive REST service? If so, how does the underlying HTTP protocol support streaming?
Related
In restful web service I read something like below ,
"The constraint to the client-server interaction is that communication must be stateless. The server should not be relied upon to maintain application state by storing session objects."
so does it mean in SOAP web services the server saves the session with them ? I have used soap user interface tool for testing the soap services in which i will be sending the request XML with all the parameters and will be getting the response, In which way restful web services differed in terms of statelessness from Soap ?
No it does not mean SOAP is stateful in all cases. Typically you design all services as stateless. Having stateful services either in SOAP or REST introduces complexity which creates all sort of problems.
However some people implement both SOAP/REST services with state and they normally aren't very successful. Maintaining state requires both the server and client to be aware of and track the current state.
So in short the principle remains never store state in a service. When calling an operation it should either return a success or failed code, it should not remember that the last operation for this client did not succeed.
Also while REST says services should be stateless you can implement it in a stateful method. Never ever go stateful it creates a lot of confusion for service consumers i.e. the client. Think about it this way if an operation is stateless you can call it and get repeatable results however if it is stateful an operation might change the results based on the state.
Also stateful operations limits scalability as it has to remember more.
My company long time ago decided to expose a JMS queue to customers in order to exchange data. We're in the process to migrate application server and we have to update all the client libraries. So we thought to expose a more "standard" interface.
We're looking to a simple way to expose a JMS queue through a standard SOAP or REST protocol. It's not SOAP over JMS, it would rather be the opposite "JMS over SOAP".
Seem that ActiveMQ(Artemis) has a REST protocol. It is a viable solution for us since we're migrating to Wildfly 10, but it's a bit complicated (see for instance posting a message requires 2 calls: see Posting Messages), and it is ActiveMQ-specific. We have to implement it again for the old Weblogic servers.
The solution we're searching for should have the same reliability of JMS, in respect of the CAP theorem (providing message deduplication on send, and idempotent reads). Any suggestion?
As per my understanding this is anti pattern where we want to combine both REST/Webservice and JMS or creating hybrid model.
JMS has strong reliability,performance,monitoring,exception handling, async response and guaranteed delivery in compared to REST/Webservice.
The only weaker point of JMS is external firewall access that can be overcomed by creating hybrid model.
Restful JMS.
http://activemq.apache.org/rest.html
http://activemq.apache.org/activesoap.html
Thanks
In developing backend components, I need to decide how these components will interact and communicate with each other. In particular, I need to decide whether it is better to use (RESTful, micro) web services versus a message broker (e.g. RabbitMQ). Are there certain criteria to help decide between using web services for each component versus messaging?
Eranda covered some of this in his answer, but I think three of the key drivers are:
Are you modeling a Request-Response type interaction?
Can your interaction be asynchronous?
How much knowledge does the sender of the information need to have about the recipients?
It is possible to do Request-Response type interactions with an asynchronous messaging infrastructure but it adds significantly to the complexity, so generally Request-Response type interactions (i.e. does the sender need some data returned from the recipient) are more easily modeled as RPC/REST interactions.
If your interaction can be asynchronous then it is possible to implement this using a REST interaction but it may scale better if you use a fire and forget messaging type interaction.
An asynchronous messaging interaction will also be much more appropriate if the provider of the information doesn't care who is consuming the information. An information provider could be publishing information and new consumers of that information could be added to the system later without having to change the provider.
Web server and message broker have their own use cases. Web server used to host web services and the message broker are use to exchange messages between two points. If you need to deploy a web service then you have to use a web server, where you can process that message and send back a response. Now let's think that you need to have publisher/subscriber pattern or/and reliable messaging between any two nodes, between two servers, between client and server, or server and client, that's where the message broker comes into the picture where you can use a message broker in the middle of two nodes to achieve it. Using message broker gives you the reliability but you have to pay it with the performance. So the components you should use depends on your use case though there are multiple options available.
I have two systems, one (let's call it S1) that exposes a RESTful API (let's call it WS1) and another one (let's call it S2) that exposes a SOAP API (let's call it WS2).
I'm trying to figure out a way to get data from S1 and add it into S2.
WS1 exposes methods for both adding/getting data (into/from S1) while WS2 only has methods for adding data (into S2).
Can these two web service communicate directly between each other or should there be some kind of mechanism in between. My guess is that "somebody should be managing their discussion".
Where are the clients?
You have a REST Server and a SOAP Server, both of their goals is to wait for requests from their respective clients -- it doesn't matter if the operations they implement read and/or write their data sets, a client still needs to initiate communication.
Bridge the gap.
Because of this you'll need a bridging client to request to read something from the REST Server and request to write something into the SOAP Server. The rest of the infrastructure for the bridge is up to you.
You can write a light script that pulls RESTful data and pushes SOAP messages for a handful of particular RESTful resources or you can write a general purpose REST2SOAP bridge which can map a RESTful resource to a SOAP message endpoint based on a conversion convention.
Direct vs. Message Queues.
Writing an abstract bridge client will allow you to run it by directly calling the REST service, receiving data, processing it, directly calling the SOAP service and sending it the data. If this is a low-load situation that's fine.
If we have a high load of data to process doing things synchronously will not be feasible, so we introduce message queues.
The producer:
reads data from the REST service;
(perhaps) processes it into a local form (which the bridge client understands such as arrays and objects);
then serializes it (serialize, json_encode, etc.);
puts it on a message queue.
The consumer(s)
listen to the message queue;
when it receives a new message it deserializes it;
processes it;
sends it to the SOAP service.
The overall advantage of the message queues is the fact that you can start up as many producers or consumers as you need depending on which of these services runs slower.
I am currently thinking about Integration styles. Following Gregor Hohpe and Bobby Woolf (http://eaipatterns.com/) the basic integration styles are
File Transfer
Shared Database
Remote Procedure Invocation
Messaging
which I understand. But which of these styles do WebServices generally apply to?
Would REST for example be a File Transfer style as it is be used to transfer resources over HTTP?
SOAP RPC applies to Remote Procedure Invocation I guess, but what about non-RPC SOAP?
WebServices could even apply to Messaging, i.e. SOAP over MQ, right?
REST calls are fundamentally Remote Procedure Invocations, as they are a lightweight way to perform method calls.
Messaging such as SOAP over MQ means looking at REST as a transport, the same way that a binary protocol over TCP is a transport.
File Transfers over HTTP, where the files are ordinary files (not XML or JSON) are no considered to be REST calls.