WSO2 Call (Blocking vs Non-blocking) vs Send Mediators - wso2

what is the difference between call mediator blocking mode and non-blocking mode? according to wso2 docs both are synchronous calls how does these differs. Please help me to understand when to use(real time integration use cases) this call mediator blocking and non-blocking mode. And in what cases send mediator will not fit only call mediator has to be used. I see call = send+respond (in one endpoint case).. what is the bestpractice to use... call or send+respond.. pls suggest

Yes your understanding is correct call mediator blocking mode and non-blocking mode both works in a synchronous manner. The call mediator in non blocking mode uses the passthrough transport and therefore has a better performance. Therefore it is recommended to use the call mediator in non blocking mode unless there is a specific requirement to use call mediator in blocking mode.
The significant difference in blocking and non blocking mode is that in the blocking mode the mediation is executed in a single thread. In the non blocking mode the thread will register a callback and that thread is released back to the pool. When a response is received a new thread will pick up the response and proceed the mediation. This will not affect the synchronous processing of mediators in the mediation. Therefore there are some use cases where it is required to execute the mediation in a single thread some of them are as follows,
In a JMS message processing scenario if you want to rollback the failed messages.
If you want to process message sequentially within a mediator such as clone mediator, iterate mediator or a message store processor use case. This means that the ESB usually process message parallelly and if you want to avoid this you will need to use blocking calls.
Regarding the send mediator it should be corrected as follows. But it has some differences. When we use a call mediator the insequence the response will come back to the insequence. After the call mediator if we use respond mediator it will respond back to the client.
call+respond = send
But when we use a send mediator in the insequence the response will come to the outsequence. This is the main functionality difference between the two mediators. Therefore when it comes to how you want to use them it depends on how you want to arrange your mediators. Further the send mediator does not have the capability to configure blocking and non blocking. It functions similar to the non blocking call mediator (in terms of thread utilization).

Related

Kurento Custom Plugin : How to send events to java server asynchronously

I am working on Kurento custom plugin, In which I have to make some curl web request and send the audio to a server and wait for server's response. I was wondering is there any way by which we can raise events to java server from kurento custom plugin synchronously. Shall I make asyc calls to raise events or make my curl calls async ?
Events fired from the media server are asynchronous. Requests, on the other hand, are synchronous, as there is only one thread attending incoming requests.
I would suggest an event-based asynchronous model in all parts, so you don't block your call to your app server. If you still want to do that, you might wrap your asynchronous event in a synchronous call. You might want to have a look at some helper classes that we use for our tests: the AsyncManager and the AsyncEventManager. You can find an example of usage in any of the tests, but maybe this one is closer to what you want to achieve.

Is usage of stream between ESB and BAM asynchronous?

I configured a BAM Server Profile and a stream in order to connect one of my Proxy Services to my BAM, I incorrectly configured the IP adress of my BAM.
When I sent a request to my proxy service, the call failed because the BAM server is not reachable. Does this mean that the exhanges between ESB and BAM is not asynchronous and can imply a failure of my proxy service?
Nicolas, every mediator is synchronous in the chain.
If you want to call the BAM asynchronously, what you need to do is:
1) Use the clone mediator to create an asynchronous thread (Sequential Mediation: NO, Continue Parent: YES). http://wso2.org/project/esb/java/4.0.0/docs/mediators/clone.html
2) In the cloned target do all your async work and place the BAM Agent Mediator.
That way you'll have your mediation working not only safer but also with better performance (since all the transformation you may need while preparing the information to be sent to BAM is happening asynchronously).
No. Although BAM mediator is synchronous as it is a mediator, data sending operation to BAM side is done asynchronously. That means if the BAM server is not reachable due to some reason (e.g., incorrect IP, BAM is not available) ESB still works properly without any problem. Only the message dumping to BAM will fail. That means mediation sequence will function properly with the server not found exception but the message logging will not happen.
During the development time of BAM mediator we considered cloning the entire message and send asynchronously to BAM side but we rejected that idea, as memory cloning will take significant time and processing which will slow down the ESB. But still data sending part (Data Bridge) works asynchronously as mentioned above.

How do JAXWS async calls work with polling

I need to invoke a long running task via a SOAP web service, using JAXWS on both ends, specifically, Apache CXF 2.6 on both ends.
I see that I can enable async methods in the CXF code generator, which creates two async methods per operation. Because of NAT issues, I cannot use WS-Addressing and callbacks. So I may want to use the other polling method.
I need to be sure that there will be no socket read timeouts using this mechanism, so I want to understand how it works.
Is it the case that a SOAP request is made to the server in a background thread which keeps the same, single, HTTP connection open, and the Future#isDone() checks to see if that thread has received a response?
If so, is there not a risk that a proxy server in between may define its own timeout, and cause an error if the server takes to long to respond?
What do other people do for invoking long running tasks via SOAP?
Yes, it would just keep checking the connection until a response is received. If something occurs between the client and server and the connection is lost, the response would not be retrievable.
For really long running things, the better approach would be to split the long running into two methods. One that would take the input and launch the work on a background thread and just return some sort of unique identifier. A second method would take that identifier and return the result. The client could call that method to kind of poll the server. That could be long running, and block or use the async methods or similar. If THAT requests times out, it could just call it again.

How to send request and receive response asynchronously to a .NET webservice by gSOAP2

I have a .NET webservice and a client program which was written by C++. The client program is using gSOAP2 to access the web service. The problem is I need to make a client request and receiving the response from server asynchronously. I search a lot by google and also read gSOAP user guide in 7.3 and 7.4 section but I still don't figure out how to do it. Please help me if you know.
Many thanks,
Tien
I don't think that gsoap means the same thing by asyncronous as you do, an asyncronous gsoap client fires of a message and then forgets about it; from reading your question my understanding is that you want to start the SOAP request/response process, go away and do something else, and then come back latter or be notified when the response has been returned.
If this is the case then I'd suggest you look at using threads to get the behaviour you want. Start a new thread to make the call, your main thread can then be notified or can check back when the call has completed. If you need data back from the call then if I was doing this I'd be tempted to write a thread that communicates via a pair of threadsafe queues. One queue to send requests into the thread and one to pass responses back out. So the main thread writes to the input queue and reads the output queue. If you search on here for C++ threadsafe queue you'll get lots more info.

http post & get is blocking call?

I see most http codes in php.
I'm about to write some http calls in c++ using CURL.
Wonder if http is inherently blocking(opposed to non-blocking).
IE, when you send get/post message, your thread is blocked until it gets the response?
If it's not, is there a way to perform non-blocking http get or post with CURL?
Thank you
HTTP is a protocol, so it's not inherently blocking or non-blocking. The only thing resembling 'blocking behavior' in HTTP is that you can't send two requests or two responses at once in the same pipeline - you have to wait for the request to finish before sending another one.
So your real question about blocking operations should be about CURL - does it allow non-blocking IO?
The answer is that libcurl has something called the 'multi interface', which enables you to use it without blocking:
http://curl.haxx.se/libcurl/c/libcurl-multi.html
If you prefer a library that's better designed towards asynchronous IO, you can check out Boost.ASIO. I've never used it myself, but it seems to be popular:
http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio.html