Invoke 3 webservices parallely and get the results consolidated in main flow service(Sync wS )

Hi All,

I have one main flow service which is Synchnous service(Request and response). It accepts wS request from source system and invoke other 3 webservices(consumers created in developer). The results received from 3 webServics will be consolidated in the main service and sends it back to Source system as wS response through webService
I want to invoke those 3 weServices parallely from web methods flow service for resolving performance issue.

Could you please help us

Note: I know Pun sub model can be used here. Detail information would be very helpful.

Thanks,
Raj

Does it involves same document type and for all the 3 consumers?

Do you currently use canonical mapping documents and Broker (pub/sub)? Yes when you say pub/sub it does publish the canonical (source) and with the trigger set it can be subscribed by multiple subscribers (interested targets) and process it further based on the destination (one ore many ERP’s/DB’s)

HTH,
RMG

Not sure if this is right answer for your requirement but anyways I will share…

1> Use publish and wait
2> Call the 3 web-services as a transformer instead of invoke so that they execute concurrently.

I’m not sure if I understood your idea with the transformers correctly, but using several transformers in one map step does not make them executed in parallel. Only the sequence they are executed in is not guaranteed for transformers in a map step.
Parallel forks in a BPMN process models get executed in parallel, but in fact there is an implicit pub/sub created here for the transitions.

Tundra, the open source package I maintain, includes a service Tundra/tundra.list.service:invoke, which can invoke multiple services concurrently.

It supports both synchronous concurrency where the number of threads used is configurable and the call to Tundra/tundra.list.service:invoke blocks until all invocations have completed, and asynchronous concurrency where the call to Tundra/tundra.list.service:invoke immediately returns a list of service threads letting you do other work in the calling service then eventually wait/block on thread completion using Tundra/tundra.list.service:join.

For example, given the following inputs (represented using JSON, for want of a better way to show the structure of an IData document list):

tundra.list.service:invoke(
  $invocations = [
    { 
      "service": "pub.string:concat", 
      "pipeline": { 
        "inString1": "abc", 
        "inString2": "def" 
      }
    },
    { 
      "service": "pub.string:toUpper", 
      "pipeline": { 
        "inString": "example" 
      }
    }
  ],
  $mode = "synchronous",
  $concurrency = 2
)

Both pub.string:concat and pub.string:toUpper will be executed concurrently with the call to Tundra/tundra.list.service:invoke blocking until both complete, and then returning the following results (again shown in JSON format):

$invocations = [
  { 
    "service": "pub.string:concat", 
    "pipeline": { 
      "inString1": "abc", 
      "inString2": "def",
      "value": "abcdef"
    }
  },
  { 
    "service": "pub.string:toUpper", 
    "pipeline": { 
      "inString": "example",
      "value": "EXAMPLE"
    }
  }
]
1 Like

Hello Lachlan Dowding ,

This is an awesome and very useful thread, Thanks a lot for posting this.

I have tried using this service.

But i have been observing that , even though i assign 7 threads i.e passed value 7 to the input concurrenct it only allccoated 2 threads in the server

P.S I have assigned 7treads becase i’m invoking a similiar service which is existing in 7 servers using wm.server.remote:invoke and trying to colloborate those results and trying too display in a DSP.

Can you please suggest on this.

Transformers won’t be executed concurrently but one by one, the order depends on the target variable (actually a method call lazySort).

Here is the sample code to invoke multiple services concurrently in local.


IDataCursor pipelineInputCursor = pipeline.getCursor();
IData[]	services = IDataUtil.getIDataArray( pipelineInputCursor, "services" );
pipelineInputCursor.destroy();
		
//Init
IData [] results = null;
ServiceThread [] threads = null;
		
//Invoke services concurrently
if ( services != null){
	results = new IData[services.length];
	threads = new ServiceThread[services.length];
	for ( int i = 0; i < services.length; i++ ){
		IDataCursor servicesCursor = services[i].getCursor();
		String	name = IDataUtil.getString( servicesCursor, "name" );
		IData	subPipeline = IDataUtil.getIData( servicesCursor, "pipeline" );	
		servicesCursor.destroy();
				
		threads[i] = Service.doThreadInvoke(NSName.create(name), subPipeline);
	}
}
		
//Check service result
for ( int i = 0; i < services.length; i++ ){
	try {
		results[i] = threads[i].getIData();
	} catch (Exception e) {
		e.printStackTrace();
	}
}
		
IDataCursor pipelineOutputCursor = pipeline.getCursor();
IDataUtil.put( pipelineOutputCursor, "results", results );
pipelineOutputCursor.destroy();