This repository provides examples of how to use the EDC connector event system which is explained in the developer documentation.
As source code, the repository Samples of Eclipse EDC has been cloned. To speed up the compilation process, only Transfer Samples has been used, so the rest of the examples have been removed.
In this basic sample a service extension is created in the ExampleEventExtension.java
file. Inside this extension the subscriber of the ExampleEventSubscriber()
event is called. This subscriber is defined in the ExampleEventSubscriber.java
file. For this sample, any event occurring in the connector will execute ExampleEventSubscriber()
and the type of event that has produced its execution will be printed.
Following the sample Write your first extension, the ExampleEventExtension.java
and ExampleEventSubscriber.java
files have been created inside the transfer/transfer-00-prerequisites/connector/src/main/java/org/eclipse/edc/sample/extension/event/
directory. The created extension has also been added to the org.eclipse.edc.spi.system.ServiceExtension
file located in the transfer/transfer-00-prerequisites/connector/src/main/resources/META-INF/services/
directory.
Clone the modified repository with the event
tag
git clone -b event https://github.com/johnnychoque/edc-conn-modif.git
Run the commands of Transfer sample 00: Prerequisites to build and execute the modified connector.
cd edc-conn-modif
./gradlew transfer:transfer-00-prerequisites:connector:build
Execute the connector as Provider for initial testing
java -Dedc.keystore=transfer/transfer-00-prerequisites/resources/certs/cert.pfx -Dedc.keystore.password=123456 -Dedc.fs.config=transfer/transfer-00-prerequisites/resources/configuration/provider-configuration.properties -jar transfer/transfer-00-prerequisites/connector/build/libs/connector.jar
Following the sample Transfer sample 01: Negotiation, open another terminal and create an asset on the Provider by running:
curl -d @transfer/transfer-01-negotiation/resources/create-asset.json \
-H 'content-type: application/json' http://localhost:19193/management/v3/assets \
-s | jq
The following message will be displayed on the terminal:
>>>>>>>>>>>>>> EVENT >>>>>>>>>>>>>
org.eclipse.edc.connector.controlplane.asset.spi.event.AssetCreated@7fb52601
This sample extends the functionality of the event subscriber previously created by sending an http request to a test server every time an event occurs.
The okhttp3
and EdcHttpClient
libraries are used to create the http requests. The EdcHttpClient library is a wrapper that uses okhttp3 to send the http requests in synchronous or asynchronous mode, but okhttp3 is also used to build the requests.
A new service extension NegotiationEventExtention.java
and a new event subscriber AgreementReached.java
are created. The org.eclipse.edc.edc.spi.system.ServiceExtension
file is modified to include the new service extension NegotiationEventExtension
instead of the previous ExampleEventExtension
.
Inside the event subscriber AgreementReached
is the sendTestMessage()
method, which sends the http request to the test server running at http://localhost:3000/
. Each time an event occurs the subscriber AgreementReached calls the sendTestMessage() method, which sends the JSON (“access_token”, “token”)
to the server.
Clone the modified repository with the request
tag
git clone -b request https://github.com/johnnychoque/edc-conn-modif.git
Build the modified comector.
cd edc-conn-modif
./gradlew transfer:transfer-00-prerequisites:connector:build
Install all the dependencies of test server
cd server-test
npm install
In a terminal run the connector as Provider for initial testing:
cd edc-conn-modif
java -Dedc.keystore=transfer/transfer-00-prerequisites/resources/certs/cert.pfx -Dedc.keystore.password=123456 -Dedc.fs.config=transfer/transfer-00-prerequisites/resources/configuration/provider-configuration.properties -jar transfer/transfer-00-prerequisites/connector/build/libs/connector.jar
In another terminal run the test server:
cd server-test
npm start
Open again another terminal and create an asset on the Provider:
curl -d @transfer/transfer-01-negotiation/resources/create-asset.json \
-H 'content-type: application/json' http://localhost:19193/management/v3/assets \
-s | jq
The following message will be displayed on the terminal:
>>>>>>>>>>>>>> EVENT >>>>>>>>>>>>>
org.eclipse.edc.connector.controlplane.asset.spi.event.AssetCreated@27a91331
{"access_token":"token"}
The terminal where the test server is running will also display the message {“access_token”: “token”}
. This is the message sent by the http POST request of the sendTestMessage() method.