Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi, I am no Java expert but I want some help to make a custom component. It's a processor component.
I got some questions here :
How to use injected services ? I try to find how but can't find a real answer.
For example, I want to use the RecordBuilderFactory. I can't create an instance of it since it's a interface and also there is this recommandation :
" If you create the instances yourself, you cannot benefit from these features, nor from the memory optimization done by the runtime. Prefer reusing the framework instances over custom ones. "
So there may be already existing instances of them.
If I declare a variable and use a method, I got the NULL pointer exception.
What I really want to know is how to create a Record( using string or any other type for example). In the documentation, there is an example :
public Record createRecord() {
return factory.newRecordBuilder()
.withString("name", "Gary")
.withDateTime("date", ZonedDateTime.of(LocalDateTime.of(2011, 2,
6, 8, 0), ZoneId.of("UTC")))
.build();
}
There is no explanation on how to have the factory instance.
And there is this recommandation :
" Record is a Java interface but never implement it yourself to ensure
compatibility with the different Talend products. Follow the guidelines
below. " means I should not implement myself the interfaces.
Hi @Fabrice Balan ,
You don't have to create services by hand, just use the annotation `@Service` ( https://github.com/Talend/component-runtime/blob/master/component-api/src/main/java/org/talend/sdk/component/api/service/Service.java ) .
Here's a sample usage : https://github.com/Talend/connectors-se/blob/master/couchbase/src/main/java/org/talend/components/couchbase/service/CouchbaseService.java#L79-L83
Hope that it will help...
Best regards.
Hi @Fabrice Balan ,
You don't have to create services by hand, just use the annotation `@Service` ( https://github.com/Talend/component-runtime/blob/master/component-api/src/main/java/org/talend/sdk/component/api/service/Service.java ) .
Here's a sample usage : https://github.com/Talend/connectors-se/blob/master/couchbase/src/main/java/org/talend/components/couchbase/service/CouchbaseService.java#L79-L83
Hope that it will help...
Best regards.
Thanks for your answer.
Should I declare them in Service class ?
Hi @Fabrice Balan ,
Not necessary but usually in your business logic modules.
best regards.
Thank you