我是Spring Cloud Dataflow的新手,正在尝试使用HTTP源,自定义处理器和Log Sink构建基本的流应用程序。我编写了一个自定义处理器,该处理器使用JAXB将从HTTP源接收到的XML记录解组到Java对象中。
自定义处理器:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.annotation.Transformer;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.Payload;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import java.io.StringReader;
@EnableBinding(Processor.class)
@SpringBootApplication
public class ProcessorApplication {
//@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
@StreamListener(Processor.OUTPUT)
@Output(Processor.OUTPUT)
public Object transform(@Payload String xmlstream) {
try{
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlstream));
Customer customer = (Customer) jaxbUnmarshaller.unmarshal(reader);
System.out.println(customer);
return customer;
}
catch (Exception e){
throw new IllegalStateException(e);
}
}
public static void main(String[] args) {
SpringApplication.run(ProcessorApplication.class, args);
}
}
这样注册处理器应用程序:
dataflow:>app register --name myprocessor --type processor --uri file://home/test/scdfCustomApps/processor-0.0.1-SNAPSHOT.jar
创建并部署流,如下所示:
stream create --name httptest --definition "http --port=9000 | myprocessor | log" --deploy
在处理器日志中,我看到以下异常:
2019-03-21 09:39:50.254错误10461 --- [ask-scheduler-1] o.s.c.s.b.k.p.KafkaTopicProvisioner:创建主题失败
org.apache.kafka.common.errors.NotControllerException:这不是 该群集的正确控制器。
2019-03-21 09:39:50.255错误10461 --- [ask-scheduler-1] o.s.cloud.stream.binding.BindingService:无法创建生产者 捆绑; 30秒后重试
org.springframework.cloud.stream.provisioning.ProvisioningException: 设置例外;嵌套异常为 org.apache.kafka.common.errors.NotControllerException:这不是 该群集的正确控制器。
问题:
版本:
Spring Cloud Dataflow Server:1.7.3
春云:Greenwich.SR1
已安装的Kafka版本:0.10