如何在Apache NiFi中用首个SOAP调用结果触发第二个SOAP调用?
Hey there! Let's break down how to chain your two SOAP calls so the second one triggers automatically using the serial number from the first. Here's a step-by-step approach that should work for you:
1. Extract the Serial Number as a Flow File Attribute
First, make sure your first Processor Group outputs a flow file with the serial number stored as an attribute. Here's how to do that:
- After your first
InvokeHTTPprocessor (the one that returns the serial number), add either anEvaluateXPath(if the SOAP response is XML) orExtractTextprocessor.- For
EvaluateXPath: Set the Destination toflowfile-attribute, define an attribute name likeserialNumber, and write the XPath expression that targets the serial number node in your SOAP response (e.g.,//ns:SerialNumber/text()wherensis your SOAP namespace). - For
ExtractText: Use a regex pattern to capture the serial number from the response body, and set the Attribute Name toserialNumber.
- For
- Add a
LogAttributeprocessor right after to verify that theserialNumberattribute is being set correctly (this helps with debugging!).
2. Use the First Flow File to Trigger the Second SOAP Call
You don't need a separate GenerateFlowFile for the second call—the flow file output from your first Processor Group is exactly what you need to trigger the second request. Here's how to configure this:
- Connect the last processor of your first group (the one that sets the
serialNumberattribute) directly to your secondInvokeHTTPprocessor. - Configure the second
InvokeHTTP's SOAP request body to reference theserialNumberattribute using NiFi's expression language. For example:- If you're using a static SOAP template, use
ReplaceTextbefore the secondInvokeHTTPto replace a placeholder with${serialNumber}. Your template might look like:<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://your.service.namespace"> <soapenv:Header/> <soapenv:Body> <ser:GetDataRequest> <ser:SerialNumber>${serialNumber}</ser:SerialNumber> </ser:GetDataRequest> </soapenv:Body> </soapenv:Envelope> - Alternatively, if you're building the request body dynamically, use
AttributeToJSONorExecuteScriptto inject theserialNumberinto the SOAP payload.
- If you're using a static SOAP template, use
3. Why Your Previous Attempts Didn't Work
Tools like RouteOnAttribute or RouteOnContent are for routing flow files to different paths based on conditions—not for generating new trigger events. The key insight here is that NiFi flows are driven by flow files themselves: each successful first SOAP call produces a flow file that carries the serial number, which can be passed directly to the second call to trigger it.
Bonus Tips
- If your first
GenerateFlowFileis set to trigger on a schedule, that's perfect for initiating the first call. The second call will run automatically every time a flow file comes out of the first group. - Use
PutAttributeif you need to rename or modify the serial number attribute before passing it to the second call. - Add a
Funnelprocessor if you need to merge multiple paths before the second call, but in your case, a direct connection should suffice.
内容的提问来源于stack exchange,提问作者TinaC

