Push notification server build on Akka Actor with Scala
Pull a docker image.
docker pull trifort/skarn
Create service.json and fill your service information.
{
"services": [
{
"name": "service1",
"auth-token": "ARBITRARY_TOKEN",
"apns": {
"cert-path": "/path/to/certificate.p12",
"password": "password"
},
"gcm": {
"api-key": "ApiKey"
}
}
]
}
Note that you need to put your APNS certificate with p12 format at the specified path.
Run a container.
docker run -v /path/to/service.json:/conf/service.json -v /path/to/certificate.p12:/path/to/certificate.p12 -e CONFIG_PATH=/conf/service.json -p 80:8080 -it trifort/skarn
If you see a log message such as "Bound to /0.0.0.0:8080", it is ready to request.
curl --header "X-AUTH-TOKEN: ARBITRARY_TOKEN" \
--header Content-Type:"application/json" \
-X POST \
http://{{YOUR_SERVER_ADDRESS}}/v1/push \
-d "{ \"notifications\": [ { \"deviceTokens\": [\"b59430...0ca3a\"], \"platform\": 1, \"body\": \"Hello iOS\" }, { \"deviceTokens\": [\"APA91bGw...Aps-jSkBUC\"], \"platform\": 2, \"title\": \"Hello Android\" } ]"
sbt
> skarn/stage
This command generates executables in api/target/universal/stage.
In addition, you can package in any other format with following commands.
- skarn/universal:packageBin - Generates a universal zip file
- skarn/universal:packageZipTarball - Generates a universal tgz file
- skarn/debian:packageBin - Generates a deb
- skarn/docker:publishLocal - Builds a Docker image using the local Docker server
- skarn/rpm:packageBin - Generates an rpm
- skarn/universal::packageOsxDmg - Generates a DMG file with the same contents as the universal zip/tgz
- skarn/windows:packageBin - Generates an MSI
For more information, see sbt-native-packager document.
You must define APNS and GCM information of your services in JSON (or HOCON) format.
example: service.json
{
"services": [
{
"name": "service1",
"auth-token": "TOKEN_IN_HEADER",
"apns": {
"cert-path": "/path/to/certificate.p12",
"password": "password"
},
"gcm": {
"api-key": "ApiKey"
}
},
{
"name": "service2",
"auth-token": "TOKEN_IN_HEADER",
"apns": {
"cert-path": "/path/to/certificate.p12",
"password": "password"
},
"gcm": {
"api-key": "ApiKey"
}
}
]
}
CONFIG_PATH=service.json ./api/target/universal/stage/bin/api
Several options are configurable via environment variables.
- CONFIG_PATH - configuration file path. See configuration section above.
- JAVA_OPTS - JVM option. Default is "-Xms256M -Xmx256M -Xss1M -XX:+UseParallelGC"
- MAX_QUEUE_SIZE - Maximum size of internal queue. Set its value as large as possible where your system memory allows. Ensure not to let it too large to prevent OutOfMemoryError. Default is 1000.
Just restart the server. Re-sending unfinished messages will be done automatically.
NOTE: Do not remove a journal
directory. It is needed for recovery.
POST /v1/push
example
{
"notifications": [
{
"deviceTokens": ["b59430...0ca3a"],
"platform": 1,
"badge": 2,
"sound": "default",
"body": "Hello iOS"
},
{
"deviceTokens": ["APA91bGw...Aps-jSkBUC"],
"platform": 2,
"title": "Hello Android",
"data": [{"key": "my-data", "value": "my-value"}],
"collapseKey": "Updates Available",
"delayWhileIdle": true
}
]
}
HEADER
- Content-Type - application/json
- X-AUTH-TOKEN - Your token defined in the config file specified by CONFIG_PATH
JSON body
Parameter | Usage | Description |
---|---|---|
notifications | Notification Array |
Array of Notification object (see below) |
Notification
Parameter | Usage | Description |
---|---|---|
deviceTokens | String Array |
array of device tokens or registration IDs |
platform | Int | APNS: 1, GCM: 2 |
title | String | notification title. Required for Android and optional for iOS. Note that in APNS, only iOS 8.2 and higher and Apple Watch support this field. |
body | Optional String |
notification body |
badge | Optional Int |
badge count. APNS only. |
sound | Optional String |
sound to be played. APNS only. |
data | Optional Object Array |
GCM data payload. Format should be array of object contains "key" and "value" fields. This array is reduced into single object. For example, [{"key": "my-data", "value": "my-value"}] turns into {"my-data": "my-value"} |
collapseKey | Optional String |
a key for collapsing notifications. GCM only. |
delayWhileIdle | Optional Boolean |
if notification should be wait or not until the device becomes active. GCM only. |
Licensed under the MIT License.