apigee using Synchronous XMLHttpRequest - apigee

When I run apigee's first JavaScript example, I get:
Synchronous XMLHttpRequest on the main thread is deprecated because of
its detrimental effects to the end user's experience. For more help,
check https://xhr.spec.whatwg.org/.
Q: Why would they be using a synchronous XMLHttpRequest? Is this first example outdated?

Related

Synchronous vs Asynchronous in Microservice pattern

What is the meaning of Synchronous and Asynchronous in general?
What are the use of Synchronous and Asynchronous communication in microservice? When to use synchronous and when to use Asynchronous.
Please explain with example thanks in advance.
Under synchronous, the communication between components is live all the time. An example would be a service making a GET/ POST call and waiting for the response to proceed to the immediate next step.
Asynchronous meaning one component does not wait for the other components to react. An example would be a service publishing message to a Kafka topic. The service which creates the event does not know when the clients will consume it.
I would start thinking about the application end-user use case to decide when I should use what.

when to use Synchronous and Asynchronous Request?

can any one explain. when to use Synchronous and Asynchronous request with example.enter code here
Generally speaking, asynchronous requests do not block the running environment until they get a response. This keeps your UI responsive while waiting for the response, and enables your user to use it. With synchronous requests, the UI would feel like it would be frozen.
I would say that while developing a web application, you would probably use asynchronous requests 99.9% of time.
From a software engineering stand of point, synchronous code is using one process, while asynchronous code executes a concurrent process. That is exactly how your UI is enabled to be responsive. It's like as if the asynchronous code ran as another program, if you will.

Guzzle vs ReactPHP vs Amphp for parallel requests

What's the difference between:
GuzzleHttp
ReactPHP
Amphp
How they differ and what would be typical use case to use with?
The main difference between those is that Guzzle is an HTTP client, while Amp and ReactPHP are generic async / event loop libraries. Both of these offer HTTP clients based on the core event loop they offer. Those are amphp/artax and reactphp/http-client.
Now, the difference between those and Guzzle is that those can do other things concurrently that are not HTTP requests. That is, because the user has full control over the event loop and can register own I/O watchers and timers, while the event loop that Guzzle uses is hidden from the user inside Curl.
If you just want to make a few concurrent HTTP requests, the decision mainly boils down to the API you like and a performance consideration maybe. If you want to do other I/O related things concurrently, use Amp or ReactPHP. If you want to stream your bodies, I'd suggest against using Guzzle, too.
Hey ReactPHP core team member here. Both ReactPHP and Amp assume you're building an app with an event loop. If you just want to do a bunch of async requests and then continue, I would suggest using Guzzle's async requests: http://docs.guzzlephp.org/en/stable/quickstart.html#async-requests
If how ever you want to dive deeper into async request I suggest https://github.com/clue/php-buzz-react which gives you more control over the process plus it supports PSR-7.

CXF Asnchronous Service Invocation

I'm looking for an example showing how can I configure my CXF project, so that I can call a service method asynchronously; meaning my invocation in the client side doesn't block for the response and when the response is ready the logic will be done. I'm very thankful if somebody can help me
Best
The simplest way is to use #Oneway annotation on the server side. CXF will handle the request on the server side in a separate thread, so the client won't be blocked and will return immediately after receiving 200 response code and empty response body.
Of course in this case you cannot receive any response (by definition of request-only SOAP operation), which is not an option for you. Unfortunately you're need to implement this by hand using thread pool and future tasks. Fortunately this is very simple since Java 5, start by studying ExecutorService API.

How can something like BOSH be implemented using Java Servlets

BOSH (Bidirectional-streams Over Synchronous HTTP) is a sneaky way of implementing 2-way client-server communication in situations where true server-push is not allowed, most obviously to let a server push data to a browser client without having to use client polling.
It works by the client sending a request to the server, and the server doesn't respond immediately... rather it remembers the request but only responds when it has some data to send. When this happens the client immediately sends another request so there is virtually always a 'stored request' sitting on the server ready to push data to the client.
At least, that's how I think it works!
Update:
My question is how you can do this using a Java EE stack i.e standard servlets. Is this possible using say Servlet 2.x (I'm a bit rusty so I don't know if you can decline to send a response or something) or only using extensions through a wrapper like Atmosphere?
Not an equivalent but Servlet 3.0 introduces an Asynchronous API. With or without Servlet 3.0, there is also Atmosphere.
See also
Servlet 3.0 Asynchronous API or Atmosphere? Easy decision!
Asynchronous HTTP and Comet architectures
Jean François Arcand blog (the author of Atmosphere)
I think this is what you might be looking for: http://blog.jwchat.org/jhb/
Maybe you are looking for something like comet, a kind of reverse AJAX in which the client initiates the connection, allowing the server to push data when it wants.
EDIT: I realize you are looking for solutions in Java and when we think of AJAX we immediately think of JavaScript, but the term has been tainted lately and it represents a concept more than a JavaScript solution. Comet is very much a concept like AJAX and can also be implemented in the programming language of your choice.

Resources