Appearance
Kafka 
往Kafka队列发送消息
业务属性 
| 属性 | 含义 | 说明 | 输入限定 | 示例值 | 
|---|---|---|---|---|
| enable | 是否启用该控件,未启用时不编译 | 是否编译 | 选择值 | 启用 | 
| name | 控件返回值命名 | 控件输出值变量名 | 常量 | kafka | 
| text | 与控件关联的文本 | 设计页控件显示 | 常量 | sendKafkaMessage | 
| kafka | 消息队列 | 可选已在资源配置中配置的Kafka队列资源 | 选择值 | myKafka | 
| topic | topic名称 | 指定发送消息的topic | 常量/流程变量 | topic1 | 
| message | 消息内容 | 发送的消息内容 | 常量,Json数据节点可用流程变量/流程变量 | {"key":"#{value}"} | 
| key | 消息分区分配的密钥 | 决定消息发送的分区 | 常量/流程变量 | #{key} | 
| throwable | 发生异常时中断请求 | 启用:控件执行异常时立即中断请求,并返回错误 禁用:控件执行异常时将被忽略,并继续执行其后的流程 | 选择值 | 启用 | 
输出值 
- 消息发送成功时输出值
控件返回以属性name为名称的实体,该实体包含属性result,并且result为boolean类型的true。
- throwable为“禁用”,消息发送失败时输出值
控件返回以属性name为名称的实体,该实体包含表示异常信息的属性err(此时属性result为nil)。
使用示例 
假设已创建Kafka资源,资源名称为:myKafka,需要向主题名称为exampleTopic发送消息。
发送常量消息 
- Kafka控件设置
添加Kafka控件并命名为sendResult,属性设置为:
kafka:mykafka; topic:exampleTopic
message:this is a example message

- 输出发送结果
添加输出控件Return,data设置为:
json
{
  "sendResult": "#{sendResult}"
}{
  "sendResult": "#{sendResult}"
}
- 接口调用
使用curl请求接口:
$ curl http://localhost:6636/api/kafka$ curl http://localhost:6636/api/kafka接口返回:
json
{
    "sendResult": {
        "result": true
    }
}{
    "sendResult": {
        "result": true
    }
}使用流程变量发送消息 
- Kafka控件设置
在前面示例的基础上,修改message属性设置为:
json
{
  "message": "#{body.message}"
}{
  "message": "#{body.message}"
}
- 接口调用
使用curl请求接口:
$ curl http://localhost:6636/api/kafka -d "{\"message\":\"This is an example message sent to kafka\"}"$ curl http://localhost:6636/api/kafka -d "{\"message\":\"This is an example message sent to kafka\"}"接口返回:
json
{
    "sendResult": {
        "result": true
    }
}{
    "sendResult": {
        "result": true
    }
}