I write a simple custom processor that adds two number then show the result. but I don't know how to show the result in the Flowfile content or attribute. after I add values in Input Value 1 & Input Value 2 properties then I run the processor the Flowfile is empty.
@Tags({"example"})
@CapabilityDescription("Provide a description")
@SeeAlso({})
@ReadsAttributes({@ReadsAttribute(attribute="", description="")})
@WritesAttributes({@WritesAttribute(attribute="", description="")})
public class MyProcessor extends AbstractProcessor {
public static final PropertyDescriptor NUMBER_1 = new PropertyDescriptor
.Builder().name("Input Value 1")
.displayName("Input Value 1")
.description("Enter the input value 1 to perform addition operation")
.required(true)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.build();
public static final PropertyDescriptor NUMBER_2 = new PropertyDescriptor
.Builder().name("Input Value 2")
.displayName("Input Value 2")
.description("Enter the input value 2 to perform addition operation")
.required(true)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.build();
public static final Relationship REL_SUCCESS = new Relationship.Builder()
.name("Success")
.description("All created FlowFiles are routed to this relationship")
.build();
private List<PropertyDescriptor> descriptors;
private Set<Relationship> relationships;
@Override
protected void init(final ProcessorInitializationContext context) {
final List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>();
descriptors.add(NUMBER_1);
descriptors.add(NUMBER_2);
this.descriptors = Collections.unmodifiableList(descriptors);
final Set<Relationship> relationships = new HashSet<Relationship>();
relationships.add(REL_SUCCESS);
this.relationships = Collections.unmodifiableSet(relationships);
}
@Override
public Set<Relationship> getRelationships() {
return this.relationships;
}
@Override
public final List<PropertyDescriptor> getSupportedPropertyDescriptors() {
return descriptors;
}
@OnScheduled
public void onScheduled(final ProcessContext context) {
}
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException {
FlowFile flowFile = session.get();
if ( flowFile == null ) {
return;
}
int num1 = Integer.parseInt(context.getProperty(NUMBER_1).getValue());
int num2 = Integer.parseInt(context.getProperty(NUMBER_2).getValue());
final String output = String.valueOf(num1 + num2);
flowFile =session.write(flowFile, new StreamCallback() {
@Override
public void process(InputStream in, OutputStream out) throws IOException {
out.write(Integer.parseInt(output));
// IOUtils.write(output, out); // writes the result to the flowfile.
}
});
session.transfer(flowFile, REL_SUCCESS);
// Transfer the output flowfile to success relationship.
}
}
how can i show the result in flowfile content or Flowfile Attribut?