REST API INTEGRATION WITH APACHE NIFI (Getting data from kafka -transform ->generate token (POST)-> post API )

491 Views Asked by At

I am trying to create a flow in Apache Nifi - Situation is like this 1- Consume message from kafka (DONE) 2- transform to a valid request body (DONE) 3- Preserve the transformed message 4- Generate a oauth2 token (it is a post api ) 5- Invoke a post api with transformed json as request body and send token in header

I have tried few ways like putting transformed json in cache and getting it after token generation but the problem is I am not able to pass token to fetchdistributedcache processor . I tried putting json file on my server but getfile doesn't take any input so not able to trigger it after getting token .

1

There are 1 best solutions below

1
Sdairs On

If Step 4 (OAuth) is returning the token as the body, there is an option in InvokeHTTP to put the response body in an attribute rather than FF content, thus preserving original FF content.

So, you could skip step 3 completely.

Consume kafka -> transformations -> InvokeHTTP for OAuth token (with Put Response Body In Attribute) -> UpdateAttribute (optional - assuming you will need to do some formatting on the response body) -> InvokeHTTP (OAuth token is already in an attribute and the FF content is unchanged)

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.12.1/org.apache.nifi.processors.standard.InvokeHTTP/