Is call-template synchronous in WSO2 - asynchronous

I'm quite new to wso2 and when using call-template I've the felling that my sequence is not called a synchronous way (the call-template is actually done in iterate mediation with sequential="true").
Can someone confirm that call-template is synchronous and if not, how to make it synchronous.
Thanks for helping

It depends on the mediation contained in your template. For exemple :
if you use clone mediator, it's targets are executed in new threads
and the iterate will continue with the next item
if you use send mediator, a callback is instanciated to receive the response and your iterate will continue the same way

Related

What is the best way to perform integration test?

Is there anyway to let rebus publish all message synchronously so that I can assert on some value after all message have been processed?
Or what is the best way to do an integration test:
Publish event
handle by saga, send command
Handle command, publish another event
Saga marked as completed
the another event handler update the database
assert or database
Thanks
Regards
Yin
For testing a single saga and its behavior you should take a look at the blog post I wrote, Unit testing sagas with Rebus, which is an example on how SagaFixture and FakeBus can be used - I think it supports everything you're mentioning that you want to test.
If you're interested in testing more complicated scenarios, possibly involving other handlers and longer message correspondences etc, you might benefit from some strategic use of ManualResetEvent - Rebus has several integration tests that start up a bus and do some stuff, doing a resetEvent.Set() when the scenario is over - this way, the test can do a resetEvent.WaitOne(timeout) to block while the test is running and continue immediately when it's over.

Implement Call queues in adhearsion

I need to implement the below use-case in asterisk + adhearsion and not sure on how to do that
When a customer call comes. I check list of available agents if the agents are busy i need to put the call in a queue with a timeout. If the agents don't become free within the given timeout the call hangs-up otherwise call gets routed to the agent.
Any idea on how to implement this flow?
There are a few ways to implement this, your approach very much depends on how will you know if an agent is available? What I would recommend is:
Call comes in
Adhearsion router, routes the call to the inbound call controller
This in bound controller checks your list of agents
If the agent is available and not on a call you can use the "dial" command to call the agent and automatically join the two calls.
If the agent is available and has an active call you can use "join"
If there are no agents available then use the "play" command to play some hold music asynchronously, while you keep checking if an agent becomes available.
When you detect an agent is available you can then "stop" the hold music and dial the call to the agent.
In order to determine which agents are available you will need some sort of agent list and their associated status which you update as they take calls. Alternatively you can try pull some of this information directly from the asterisk extensions.conf file, or the DB if you are using PIAF.
Most of the code examples you need to write something like this are given on the Adhearsion website. http://www.adhearsion.com/docs
Edit:
The better way of approaching this now will be to use the ElectricSlide call queue module. There has been a lot of work done on it recently and it is now a pretty solid call queue.
https://github.com/adhearsion/electric_slide/

Invoking a Process On server startup

I have a process which I will be invoking manually for the first time in prod environment. Thing is, the process stops when the server is down or if the server is stopped. In this scenario, I will not be able to invoke the process manually everytime since it will be in production environment and not feasible also. So i need to know how can i invoke a process automatically once the server is up?
Heard that one way is to write a custom component to start the process using livecycle implementation class.
Please let me know how to go about it?
Any help regarding this is much appreciated!
Thanks
There are at least two ways you can do this.
First is the custom component route. You invoke the process on component life-cycle start to ensure that the invocation happens every time your component is deployed.
Second is the servlet route. You invoke the process on the initialisation of the servlet making sure that the server started.
The servlet implementation is a better fit for purpose, the only downside is, you need to package and deploy it separately as it won't be a part of the LCAs.
You can find the code samples on how to invoke LC processes using APIs on adobe docs. You can use Java API, WS API or Rest, whichever you are more comfortable with.
http://help.adobe.com/en_US/livecycle/9.0/programLC/help/index.htm

node.js asynchronous initialization issue

I am creating a node.js module which communicates with a program through XML-RPC. The API for this program changed recently after a certain version. For this reason, when a client is created (createClient) I want to ask the program its version (through XML-RPC) and base my API definitions on that.
The problem with this is that, because I do the above asynchronously, there exists a possibility that the work has not finished before the client is actually used. In other words:
var client = program.createClient();
client.doSomething();
doSomething() will fail because the API definitions have not been set, I imagine because HTTP XML-RPC response has not returned from the program.
What are some ways to remedy this? I want to be able to have a variable named client and work with that, as later I will be calling methods on it to get information (which will be returned via a callback).
Set it up this way:
program.createClient(function (client) {
client.doSomething()
})
Any time there is IO, it must be async. Another approach to this would be with a promise/future/coroutine type thing, but imo, just learning to love the callback is best :)

WebRequest and WebService call asynchronously in C#

I have MVC application (applies to non MVC as well) where a user is posting in data. I need to take this data, send it off to two seperate end points (one using a WebRequest form POST and one using a Web Service), parse the result, and send the result back to the original user.
The issue at hand is that both end points take about 20-30 seconds to respond (response is a string) which means that I should probably execute these two calls asynchronously. At the same time I want to wait to respond to the original user until I get both results back. I am guessing I might have to use some sort of object lock so the response does not get sent back before the two calls are complete?
Am I on the right path? Does anyone have any information on how to achieve this? Any help is appreciated.
Thanks
EDIT
Based on the responses I decided to go with async controllers since I am already working with a MVC application. Thank you for your input.
You can invoke Join on the two asynchronous threads to wait for their return. You'll also want to look into asynchronous controllers. This is available in MVC2 but you can also look at the MVC1 features I believe to implement asynchronous actions. You'll want to do this so you're not blocking IIS from processing more threads.
I think you'll find this helpful: Rx: Piecing together multiple IObservable web requests
In particular, using ForkJoin to wait until both responses come back as mentioned in the comments:
Also bonus question, there is a case where I would like to execute web calls simultaneously
and when all are finished execute another observable which will until other calls are finished.
Use Observable.ForkJoin to execute
multiple async calls simultaneously
and then join all of the results into
a single IObservable. Then use
SelectMany (another from statement)
just like above, to subscribe to
another observable based on the joined
result.

Resources