嘿,我正在使用kStreams向主题发送消息。我的留言是一个字符串。
我想向其中添加一些标头,以便最终系统可以根据标头过滤掉。
我试图在所有地方找到,但找不到可靠的答案
这是我正在使用的一些代码。
公共类处理器{ 私有静态最终字符串APPLICATION_ID =“ output-actor”;
public void process() {
KafkaStreams kafkaStreams = new KafkaStreams(topology(), config());
kafkaStreams.start();
}
private Properties config() {
return KafkaUtil.getStreamsApplicationProperties(APPLICATION_ID);
}
private Topology topology() {
final Serde<String> stringSerde = Serdes.String();
StreamsBuilder builder = new StreamsBuilder();
KStream<String, Transaction> potaPi = builder.stream(inputTopic(), consumeTransactionResult())
.filter(isNull())
.filter(sourceSystemFilter())
.filter(currentStateValidation())
.mapValues(ormToPotapi())
.filter(applyGLPSourceSystemFilter());
potaPi.map(transactionToXMLString())
.to(cintOutputTopic(), Produced.with(stringSerde, stringSerde));
return builder.build();
}
private Predicate<String, Transaction> applyGLPSourceSystemFilter() {
GLPSourceSystemFilter glpSourceSystemFilter = new GLPSourceSystemFilter();
return new TransactionContainsGLPSource(glpSourceSystemFilter);
}
private String cintOutputTopic() {
return SystemUtil.getEnvironmentVariable("CINT_OUTPUT_TOPIC", "prod-glp-se-customs-address-write");
}
private KeyValueMapper<String, Transaction, KeyValue<String, String>> transactionToXMLString() {
return new TransactionToGLPXMLMapper();
}
private ValueMapper<TransactionResult, Transaction> ormToPotapi() {
return new OrmToPotapiMapper();
}
private Predicate<String,TransactionResult> isNull() {
return (k , v ) -> v != null;
}
private Predicate<String, TransactionResult> sourceSystemFilter() {
return (key,
transactionResult) -> ((null != transactionResult.getTransaction().getBundle().getItems() && transactionResult.getTransaction().getBundle().getItems().size() > 0) &&
(transactionResult.getTransaction().getBundle().getItems().get(0).getSource()
.toString().equalsIgnoreCase("POTAPI/ASTA")));
}
private Predicate<String, TransactionResult> currentStateValidation() {
return (key,
transactionResult) -> (null != transactionResult.getTransaction().getBundle().getOrders() && transactionResult.getTransaction().getBundle().getItems().size() > 0);
}
private Consumed<String, TransactionResult> consumeTransactionResult() {
Serde<String> keySerde = Serdes.String();
Serde<TransactionResult> valueSerde = TransactionSerde.transactionResult();
return Consumed.with(keySerde, valueSerde);
}
private String inputTopic() {
return SystemUtil.getEnvironmentVariable("INPUT_TOPIC", "transaction-commit");
}
}