Public | Automated Build

Last pushed: 2 months ago
Short Description
Proactively notifies subscribers about new content publishes/modifications.
Full Description


Notifications-push is a microservice that provides push notifications of publications or changes of articles and lists of content.
The microservice consumes a specific Apache Kafka topic group, then it pushes a notification for each article or list available in the consumed Kafka messages.

How to Build & Run the binary

  1. Install, build and test:
    go get -u
    go get -u
    cd $GOPATH/src/

govendor sync
govendor test -v -race
go install

2. Run locally:

* Create tunnel to the Kafka service inside the cluster for ports 2181 and 9092 (use the public IP):

ssh -L 2181:localhost:2181 -L 9092:localhost:9092 username@<host>

* Add the private DNS of the Kafka machine to the hosts file: <private_dns>

* Start the service using environment variables:

&& export KAFKA_ADDRS=localhost:2181 \
&& export GROUP_ID=notifications-push-yourtest \
&& export TOPIC=PostPublicationEvents \
&& export API_BASE_URL="" \
&& export WHITELIST="^http://(methode|wordpress|content)-(article|collection|content-placeholder)-(transformer|mapper|unfolder)(-pr|-iw)?(-uk-.)?\.svc\.ft\.com(:\d{2,5})?/(content)/[\w-]+.$" \
&& ./notifications-push

* or via command-line parameters:

./notifications-push \
--notifications_resource="content" \
--consumer_addr="localhost:2181" \
--consumer_group_id="notifications-push" \
--topic="PostPublicationEvents" \
--notifications_delay=10 \
--api-base-url="" \
--api_key_validation_endpoint="t800/a" \

NB: for the complete list of options run `./notifications-push -h`

HTTP endpoints
```curl -i --header "x-api-key: «api_key»"

The following content types could be also specified for which the client would like to receive notifications by setting a "type" parameter on the request: Article, ContentPackage and All to include everything (also CPHs).
If not specified, by default Article is used. If an invalid type is requested an HTTP 400 Bad Request is returned.

curl -i --header "x-api-key: «api_key»"

Push stream

By opening a HTTP connection with a GET method to the /{resource}/notifications-push endpoint, subscribers can consume the notifications push stream for the resource specified in the configuration (content or lists).
The stream will look like the following one.

data: []

data: []

data: [{"apiUrl":"","id":"","type":"","title":"For Ioana & Ioana only;","standout":{"scoop":true}}]

data: []

data: []

data: []

data: [{"apiUrl":"","id":"","type":"","title":"For Ioana 2","standout":{"scoop":false}}]

data: []

data: [{"apiUrl":"","id":"","type":"","title":"For Ioana 3","standout":{"scoop":false}}]

data: [{"apiUrl":"","id":"","type":"","title":"For Ioana 4","standout":{"scoop":false}}]

data: [{"apiUrl":"","id":"","type":"","title":"For Ioana 4","standout":{"scoop":false}}]

The empty [] lines are heartbeats. Notifications-push will send a heartbeat every 30 seconds to keep the connection active.

The notifications-push stream endpoint allows a monitor query parameter. By setting the monitor flag as true, the push stream returns publishReference and lastModified attributes in the notification message, which is necessary information for UPP internal monitors such as PAM.

To test the stream endpoint you can run the following CURL commands :

curl -X GET "http://localhost:8080/content/notifications-push"
curl -X GET "http://localhost:8080/lists/notifications-push?monitor=true"
curl -X GET "https://<user>@<password>"

WARNING: In CoCo, this endpoint does not work under /__notifications-push/ and /__list-notifications-push/.
The reason for this is because Vulcan does not support long polling of HTTP requests. We worked around this issue by forwarding messages through Varnish to a fixed port for both services.

Productionizing Push API:
The API Gateway does not support long polling of HTTP requests, so the requests come through Fastly. Everytime a client tries to connect to Notifications Push, the service performs a call to the API Gateway in order to validate the API key from the client.

Notification history

A HTTP GET to the /__history endpoint will return the history of the last notifications consumed from the Kakfa queue.
The expected payload should look like the following one:

        "apiUrl": "",
        "id": "",
        "type": "",
        "publishReference": "tid_jwhfe7n6dj",
        "lastModified": "2016-11-07T13:59:44.950Z"
        "apiUrl": "",
        "id": "",
        "type": "",
        "publishReference": "tid_owd5zqw11m",
        "lastModified": "2016-11-07T13:59:04.546Z"
        "apiUrl": "",
        "id": "",
        "type": "",
        "publishReference": "tid_5z8dxzsesj",
        "lastModified": "2016-11-07T13:58:36.285Z"


A HTTP GET to the /__stats endpoint will return the stats about the current subscribers that are consuming the notifications push stream
The expected payload should look like the following one:

    "nrOfSubscribers": 2,
    "subscribers": [
            "addr": "",
            "since": "Nov  7 14:26:04.018",
            "connectionDuration": "2m41.693365011s",
            "type": "dispatcher.standardSubscriber"
            "addr": "",
            "since": "Nov  7 14:26:06.259",
            "connectionDuration": "2m39.453175004",
            "type": "dispatcher.monitorSubscriber"

How to Build & Run with Docker

    docker build -t coco/notifications-push .

    docker run --env NOTIFICATIONS_RESOURCE=content \
        --env KAFKA_ADDRS=localhost:2181 \
        --env GROUP_ID="notifications-push-yourtest" \
        --env TOPIC="PostPublicationEvents" \
        --env NOTIFICATIONS_DELAY=10 \
        --env API_BASE_URL="" \
        --env WHITELIST="^http://(methode|wordpress|content)-(article|collection)-(transformer|mapper|unfolder)(-pr|-iw)?(-uk-.*)?\\.svc\\.ft\\.com(:\\d{2,5})?/(content)/[\\w-]+.*$" \


Example client code is provided in bin/client directory

Useful Links

  • Production: (needs API key) (needs API key)

  • For internal use: (needs credentials) (needs credentials)

Docker Pull Command