I want to run hazelcast-jet
embedded in my spring application (ie cluster is in process / NOT remote). I also want my jet jobs to be able to access spring beans from the ApplicationContext
(see jet/spring docs). I don't want to have to configure the classpath on each jet job, I want to use the JVM's bootstrap classpath.
I think I need to use Jet.bootstrappedInstance()
to get a JetInstance
but this does NOT allow me to set the ManagedContext
on the underlying HazelcastInstance
. The docs from Jet.bootstrappedInstance()
detail the way in which I want to interact with Jet
When you submit a job to a Jet instance that runs locally in your JVM, it will have all the dependency classes available
I've tried this:
@Bean
public ManagedContext managedContext() {
return new SpringManagedContext();
}
@Bean
public JetInstance jet(ManagetContext managedContext, List<Pipeline> pipelines) {
JetInstance jet = Jet.bootstrappedInstance();
jet.getHazelcastInstance().getConfig().setManagedContext(managedContext);
...
return jet;
}
But I get the following exception
Caused by: java.lang.UnsupportedOperationException: Unsupported operation
at com.hazelcast.internal.dynamicconfig.DynamicConfigurationAwareConfig.setManagedContext(DynamicConfigurationAwareConfig.java:981)
Please note that the normal way of calling setManagedContext(...) is like this
JetConfig config = new JetConfig();
config.configureHazelcast(hz -> hz.setManagedContext(managedContext));
JetInstance jet = Jet.newJetInstance(config);
I can't find a way of combining Jet.bootstrappedInstance()
with Config.setManagedContext(ManagedContext)
As a workaround, I've copied code from JetBootstrap.createStandaloneInstance()
(a private method) and added hzConfig.setManagedContext(managedContext)
JetConfig config = ConfigProvider.locateAndGetJetConfig();
Config hzConfig = config.getHazelcastConfig();
// turn off all discovery to make sure node doesn't join any existing cluster
hzConfig.setProperty("hazelcast.wait.seconds.before.join", "0");
hzConfig.getAdvancedNetworkConfig().setEnabled(false);
hzConfig.setManagedContext(managedContext);
JoinConfig join = hzConfig.getNetworkConfig().getJoin();
join.getAutoDetectionConfig().setEnabled(false);
join.getMulticastConfig().setEnabled(false);
join.getTcpIpConfig().setEnabled(false);
join.getAwsConfig().setEnabled(false);
join.getGcpConfig().setEnabled(false);
join.getAzureConfig().setEnabled(false);
join.getKubernetesConfig().setEnabled(false);
join.getEurekaConfig().setEnabled(false);
join.setDiscoveryConfig(new DiscoveryConfig());
JetInstance jet = Jet.newJetInstance(config);