Custom Output Adapter Basics
For your custom output adapter to be successful, it should implement certain methods. Once completed, register your adapter as a custom bean in your Spring configuration file.
Ideal Target System Architecture
To reduce network-related points of failure, latency, and overhead, we recommend that the target system supports batch imports. In this way, low-level data bursting and update logic happens on the target system. The export should therefore be asynchronous, and the target system then must inform Data Hub when the import has been completed. The targey system can accomplish this through a REST call that delegates to the PublicationActionService (see Publication Completion).
Implementation Basics
An output adapter is an implementation of the com.hybris.datahub.adapter.AdapterService interface. When implementing this interface, provide the following two methods:
-
getTargetSystemType()
This method returns the target system type name as defined in the targetSystem <type> node in the associated target extension XML.
-
publish(TargetSystemPublication publication, String serverURL)
This method is expected to perform the following:- Retrieve all target items associated with the current publication
- For each target item, issue the appropriate insert, update, or delete transactions to the target system
public class myAdapterService implements AdapterService { @Override public void publish(final TargetSystemPublication targetSystemPublication, final String serverURL) throws PublicationException { Preconditions.checkArgument(targetSystemPublication != null && targetSystemPublication.getTargetSystem().getTargetSystemType().equals(getTargetSystemType())); Preconditions.checkArgument(StringUtils.isNotEmpty(serverURL), "Server url must be provided."); final List<TargetItems> contentList = createTargetItemsToExport(targetSystemPublication, serverURL); myAdapterPublicationService.publish(targetSystemPublication, contentList, serverURL); } //Custom adapter implementation here. } -
As a result of calling the publish method, the following must also occur:
- Collect any errors resulting from the target system interaction
- Notify the PublicationActionService that the publication has been completed, while reporting any errors that occurred in the process
Configuration
Once your adapter is complete, register it in your extension Spring context, so it becomes available for Data Hub. For example:
mycompany-datahub-extension-spring.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<description>
Defines the Spring beans for the mycompany extension module. Depends on datahub Spring beans, but does not
need an import.
</description>
<alias name="defaultDevNullAdapterService" alias="devNullAdapterService" />
<bean name="defaultDevNullAdapterService" class="com.mycompany.datahub.adapter.devnull.DevNullTargetAdapter" />
</beans>
The name of the bean is not important, because the adapter injects into Data Hub by type. If the class implements the AdapterService interface, it is automatically registered as a target system adapter inside Data Hub. The registration assumes the extension jar (and therefore the Spring XML file) is in the folder /opt/datahub/extensions/. You may include configuration parameters and references to other services as properties in your bean definition.
What's next?
Once you have the basic framework for your adapter, you want to start connecting to your target system. The following topic walks you through some key aspects of implementing this step.