I have a JAX-RS web service.
One of the operations may take a long time so I need to make this an asynchronous REST call and then callback the client once it's complete.
I read about "WebHooks" and wonder is there a sample implementaion I can follow?
http://www.infoq.com/news/2009/07/AsynchronousRest
Related
There are many articles out there that recommend using ngrx/effects for handling async actions such as http REST calls. Instead of using effects, why can't we just use a regular service to make the http call and then take the result of that http call and dispatch an action? Doesn't that simplify things?
You can perfectly use a regular service and then dispatch an action, like this on a component.
this.store.dispatch({
type: "SAVE_DATA",
payload: data
});
this.saveData(data) // POST request to server
.map(res => this.store.dispatch({type: "DATA_SAVED"}))
.subscribe()
#ngrx/effect just abstracts this logic away from the component. By doing this with a functional programmic aproach (pure functions), code remains very easy to test.
I really recommend reading this article, since there are many solutions to problems that abuse effects
Post
Using ngrx/effects makes life more simpler than using service to make http call and then take the result and dispatch the action. As following
Effects provide abstraction to the service layer. Our components don't need to know about the services(http) layer. Components will only dispatch actions to get things done.
As Effects are basically service, code is written once and reused multiple times.
I'm new to Play, so bear with me. I'd like to understand the "reactiveness" of Play and how to best make use of it.
My web application needs to do the following:
Receive an HTTP request (json format)
Pass the request to a controller
The controller needs to read a table (using Slick)
The controller needs to populate a response (json format)
The response is sent back to the browser
If I understand correctly, the application is Reactive when it uses asynchronous function calls to improve performance as a thread may be doing more that one thing at a specific time. But I don't see how the web application that I described can call a method and not wait for a response, there's nothing to do in parallel. What am I missing?
How do I send POST/PUT/DELETE calls to a rest source using Atmosphere 1.1.0+ in a conventional RPC manner? (You are guessing right, I want to employ pub/sub and RPC style in my project)
serverside: register a #Path (e.g. /member), mark with #POST/#PUT/#DELETE, process the method body and return the value. Seems straight forward. Even with JSON en-/decoding.
clientside: How would you kick a POST request with the wasync library? All atmosphere examples use "GET" and recommended to use GET only. Why is that?
RequestBuilder request = client.newRequestBuilder().method(Request.METHOD.GET).uri("/member")
Can one expect this synchronous server response when invoking the fire method? e.g.
Future future = socket.fire(myMemberObject)
Thank you for hints and comments on this approach (also thoights on pairing RPC and PubSub are welcome).
wAsync is using POST once the connection is established. wAsync is asynchronous by nature so you need to use Latch if you want to make it blocking, or use AsyncHttpClient with Future.
I have one web service method it is taking long time to run. i want to make it asynchronous
and web service client should not wait for web method to complete. How i could implement this on c#.
//Web Method
[WebMethod]
public void StartProcess()
{
//long running method
}
//Web Client
webService.StartProcess();
Generate your service reference or edit it by choosing async option in VS, now the generation process will create two calls and one will be yourMethodAsync that you can call. You can also setup a callback this way.
Also you can use parallel tasks in C# to put a call on a background thread. I prefer to generate the async methods since it is cleaner.
here is a post that will help
what is the need to create Async and Sync interface in client package and its impl class in Server package when need to impelement RPC in GWT. What is the need to create Sync as well as Async interface in GWT for successful RPC.
In a nutshell: Async is needed for client side, Sync is needed for server side.
All RPC (XmlHttpRequest) calls in Javascript are asynchronous - when network call is finished, your code is called with result.
So on client side with GWT RPC you must provide an Async interface (and implementation of it) in order to be called when results are available.
You must also provide related Sync interface which is implemented on server side.
There is a contract on how Async and Sync interface must be written: http://code.google.com/webtoolkit/doc/latest/tutorial/RPC.html
well I assume that you know that any JS in browser is kind of synchronous event driven.
To responce to the RPC you need a callback.
So when writing Java code you need to pass the callback object to a call.
but the server side is a simple method call with return type that should match the parameter of the callback. Right?
So here you get 2 interfaces that all together give you full type safety at compile time. and allows it all work smooth as it does.