Open Content
Docs homeNaviga web
  • Introduction
  • Overview
  • Key features
  • Meta data standards
  • Architecture
  • Open Content API
  • Headless and end-to-end CMS workflows
  • Use and explore
    • How does it work
    • Open Content Docker
    • OC REST API
    • Event logs
    • Replication
    • Open Content Notifier
    • New JSON API:s - CCA and Duppy
    • Terminology: Other backend services
    • Lab: upload
      • Curl for object upload
      • Environment
      • Lab 0: Configuration
      • Lab 1: Concept upload
      • Lab 2: Image upload
      • Lab 3: Article Upload
      • Lab 4: Search
      • Lab 5: Delete objects
      • Lab 6: Event sourcing using event log
  • Releases
    • Release documentation and admin guides
      • Open Content 2.3
    • New in OC 3.0 (draft)
      • Removed features in OC 3.0
  • XLibris Archive
    • Archive everything you ever created or published
    • Import content to XLibris
Powered by GitBook
On this page
Export as PDF
  1. Use and explore
  2. Lab: upload

Lab 6: Event sourcing using event log

Show how to use the Open Content event log

In this exercise you will start a script which will poll the Open Content event log every 5th second. If any events are found the script will print information of the event.

The script will persist the last event to a file (lastevent) which holds the last event id processed by the script. When started next time and lastevent file exists the script will start processing events with id larger than the lastevent processed . This means that even if the listener is off. It will continue from last event next time the listener is started. This way no event is missed.

This is how to get the /eventlog/ endpoint response:

 curl -s -u admin:admin localhost:8080/opencontent/eventlog?event=0| jq .

Response

{
  "events": [
    {
      "id": 1,
      "uuid": "8c7437ce-a7ca-414d-8bfc-7bf2d1054fc3",
      "eventType": "ADD",
      "created": "2019-06-14T09:32:23.000Z",
      "content": {
        "uuid": "8c7437ce-a7ca-414d-8bfc-7bf2d1054fc3",
        "version": 1,
        "created": "2019-06-14T09:32:22.000Z",
        "source": "lab-hans.bringert",
        "contentType": "Concept",
        "batch": false
      }
    },
    {
      "id": 2,
      "uuid": "db09e859-43d4-42f8-a6ca-c810b653ec6a",
      "eventType": "ADD",
      "created": "2019-06-14T09:32:23.000Z",
      "content": {
        "uuid": "db09e859-43d4-42f8-a6ca-c810b653ec6a",
        "version": 1,
        "created": "2019-06-14T09:32:23.000Z",
        "source": "lab-hans.bringert",
        "contentType": "Concept",
        "batch": false
      }
    }
  ]
}

Get the last event id use event=-1

curl -s -u admin:admin localhost:8080/opencontent/eventlog?event=-1| jq .
{
  "events": [
    {
      "id": 20,
      "uuid": "0a18480e-1486-4ce5-8f61-ebb67d3d8938",
      "eventType": "DELETE",
      "created": "2019-06-14T09:35:01.000Z",
      "content": {
        "uuid": "0a18480e-1486-4ce5-8f61-ebb67d3d8938",
        "version": 1,
        "created": "2019-06-14T09:32:37.000Z",
        "source": "lab-hans.bringert",
        "contentType": "Article",
        "batch": false
      }
    }
  ]
}

In folder 6-event-sourcingis an example of a bash script which will poll the event log every 5 seconds and print information about what is happening. To try this :

./listen.sh
Url [http://127.0.0.1:8080] :
Username  [admin]:
Password  [admin]:
0
'lastevent' file is missing last event in Open Content is:  20

Now the script polls the event log every 5 second and print out the events.

PreviousLab 5: Delete objectsNextRelease documentation and admin guides

Last updated 5 years ago

Have the listener in a terminal window and add/modify/delete the items in Open Content and see the events.