nifi发送http请求

流程概述:从kafka中消费json串,取json中的某几个属性值,作为参数进行http请求(GET请求或POST请求),接收返回参数存入文件,总流程如下。
nifi发送http请求_第1张图片
ConsumeKafka:消费kafka中json串,如:
{“id”:”111”,”userName”:”你好”}
EvaluateJsonPath:通过添加Property取json串中某几个属性的值,传出的数据只有值。可添加多个,若有多个需要传入参数,就添加多个property。
Destination:选择flowfile-Attribute 将添加的property作为flowfile的attribute传出。
nifi发送http请求_第2张图片
AttributeToJson:将上个节点传出的attribute转换成json,将转换后的json作为flowfile传出。
nifi发送http请求_第3张图片
Attribute List:为需要转换成json的attribute。
Destination:为将转换后的json作为flowfile传出。
InvokeHTTP:发送GET或POST请求,请求参数由上一个节点传入。
nifi发送http请求_第4张图片
HTTP Method:为请求方式。
Remote URL:为请求路径。
nifi发送http请求_第5张图片
Content-type:为传入数据格式,application/json表示传入数据为json格式,charset=UTF-8为传入数据的编码格式。
UpdateAttribute:接收返回值。
PutFile:将返回数据放入文件中查看输出。
例:kafka中消费的json为:
{“id”:”111”,”userName”:”小明”}
请求ip:8080/test的Controller为

@RestController
public class UserTest {

    @RequestMapping("/getUser")
    public User getUser(@RequestBody User user) {

        System.out.println(user.toString());
        user.setId(1);
        user.setAddress("北京");
        return user;
    }

}

其中userName为传入参数,id和address为我controller中的人为设置,返回数据为user对象。
从文件中查看到的返回值如下
这里写图片描述

你可能感兴趣的:(nifi,kafka)