|
| 1 | +--- |
| 2 | +description: Documentation on how to connect to Hopsworks from a Java client. |
| 3 | +--- |
| 4 | + |
| 5 | +# Java client |
| 6 | + |
| 7 | +This guide explains step by step how to connect to Hopsworks from a Java client. |
| 8 | + |
| 9 | + |
| 10 | +## Generate an API key |
| 11 | + |
| 12 | +For instructions on how to generate an API key follow this [user guide](../projects/api_key/create_api_key.md). For the Java client to work correctly make sure you add the following scopes to your API key: |
| 13 | + |
| 14 | + 1. featurestore |
| 15 | + 2. project |
| 16 | + 3. job |
| 17 | + 4. kafka |
| 18 | + |
| 19 | +## Connecting to the Feature Store |
| 20 | + |
| 21 | +You are now ready to connect to the Hopsworks Feature Store from a Java client: |
| 22 | + |
| 23 | +```Java |
| 24 | +//Import necessary classes |
| 25 | +import com.logicalclocks.hsfs.FeatureStore; |
| 26 | +import com.logicalclocks.hsfs.FeatureView; |
| 27 | +import com.logicalclocks.hsfs.HopsworksConnection; |
| 28 | + |
| 29 | +//Establish connection with Hopsworks. |
| 30 | +HopsworksConnection hopsworksConnection = HopsworksConnection.builder() |
| 31 | + .host("my_instance") // DNS of your Feature Store instance |
| 32 | + .port(443) // Port to reach your Hopsworks instance, defaults to 443 |
| 33 | + .project("my_project") // Name of your Hopsworks Feature Store project |
| 34 | + .apiKeyValue("api_key") // The API key to authenticate with the feature store |
| 35 | + .hostnameVerification(false) // Disable for self-signed certificates |
| 36 | + .build(); |
| 37 | + |
| 38 | +//get feature store handle |
| 39 | +FeatureStore fs = hopsworksConnection.getFeatureStore(); |
| 40 | + |
| 41 | +//get feature view handle |
| 42 | +FeatureView fv = fs.getFeatureView(fvName, fvVersion); |
| 43 | + |
| 44 | +// get feature vector |
| 45 | +List<Object> singleVector = fv.getFeatureVector(new HashMap<String, Object>() {{ |
| 46 | + put("id", 100); |
| 47 | + }}); |
| 48 | +``` |
| 49 | + |
| 50 | +## Next Steps |
| 51 | +For more information how to interact from Java client with the Hopsworks Feature store follow this [tutorial](https://github.com/logicalclocks/hopsworks-tutorials/tree/java_engine/java). |
0 commit comments