-
Notifications
You must be signed in to change notification settings - Fork 12
Astrix Plugins
Elias Lindholm edited this page Oct 24, 2015
·
6 revisions
This is a very early draft
Astrix provides a number of extension points, where some of the more important are:
ServiceComponent
ServiceDiscoveryFactoryPlugin
BeanPublisherPlugin
This part describes how you plug-in your custom extensions into Astrix at runtime.
Astrix allows for two different types of extensions, plugins and strategy. Put simply, there might be an arbritrary number of a given plugin type (for instance ServiceComponent
plugins), as opposed to a strategy where Astrix assumes exactly one instance at runtime.
A plugin is created by implementing the AstrixContextPlugin
interface. It contains one non-default method:
public interface AstrixContextPluign {
void prepare(ModuleContext moduleContext);
}
@MetaInfServices(AstrixContextPlugin.class)
public class CustomRemotingModule implements AstrixContextPlugin {
@Override
public void prepare(ModuleContext moduleContext) {
// 1.
moduleContext.bind(ServiceComponent.class, MyCustomRemotingComponent.class);
// 2.
moduleContext.importType(AstrixServiceActivator.class);
moduleContext.importType(ObjectSerializerFactory.class);
moduleContext.importType(RemotingProxyFactory.class);
moduleContext.importType(AstrixConfig.class);
// 3.
moduleContext.export(ServiceComponent.class);
}
}
- Setup internal bindings used for dependency injection within the component, see astrix-modules
- Import components from the AstrixContext
- Export the
ServcieComponent
type from this module
Astrix uses the java ServiceLoader mechanism to load plugins at runtime.
com.mycorp.astrix.ext.CustomRemotingModule
@MetaInfServices(AstrixContextPlugin.class)
public class MyCustomHystrixCommandNamingStrategy implements AstrixContextPlugin {
@Override
public void registerStrategies(AstrixStrategiesConfig strategiesConfig) {
strategiesConfig.registerStrategy(HystrixCommandNamingStrategy.class, MyCustomHystrixCommandNamingStrategy.class);
}
@Override
public void prepare(ModuleContext moduleContext) {
}
}
Strategies are loaded in the same way as a plugin.