For example, given a simple pipeline such as:
Pipeline p = Pipeline.create();
p.readFrom(TestSources.items("the", "quick", "brown", "fox"))
.map(mapFn)
.writeTo(Sinks.logger());
I'd like mapFn
to be something requiring a non-serialisable dependency to do its work.
I know I can do this:
Pipeline p = Pipeline.create();
p.readFrom(TestSources.items("the", "quick", "brown", "fox"))
.mapUsingService(JetSpringServiceFactories.bean("myDependencies"),
MyDependencies::addDependencies);
.map(mapFn)
.writeTo(Sinks.logger());
This wraps the strings being read from the source in another object that includes the dependencies, giving mapFn
access to those dependencies without them needing to be injected into that object itself. That will work, but I want to use my mapping function outside Jet as well as part of a pipeline, and in that case it's a bit weird to have to pass dependencies along with the items being mapped rather than just initialising the mapper with the dependencies it needs. It also forces me to pointlessly create a wrapper object per item in my stream/batch.
The docs say another alternative is to use the @SpringAware
annotation on Processor
, but I think that means using the Core API, which the docs says "mostly offers you a lot of ways to make mistakes", so I'd prefer to avoid that.
In vanilla Hazelcast IMDG, anything that is deserialised can use a ManagedContext
to initialise itself, and this is obviously the case with Jet too, but the functions, filters etc. of the pipeline are wrapped in lots of layers of Jet pipeline stuff and so there seems to be no way to get to them.
Am I missing something or have I listed all the options I have (other than resorting to some "global" static
dependencies object)?