Skip to content

nikola-mladenovic/notification-service-iron-worker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IronWorker Notification Service Example for Sunrise iOS App

Sunrise iOS app push notifications are triggered using Commercetools subscriptions. One of the possible destinations for a subscription is an IronMQ. Messages published to an IronMQ can trigger IronWorker if subscribed. This example will show you how you can easily get notifications to your mobile shop app running on Commercetools platform, without a need for a server instance. The scope of this example covers reservation notification scenario, triggered on OrderCreated message.

Setup

Credentials

In order to use this example you need:

  • An active Commercetools project. Replace PROJECT_KEY, SCOPE, CLIENT_ID, CLIENT_SECRET, API_URL and AUTH_URL with values valid for your project.
  • Docker Hub account for pushing the Docker image built from the NotificationUtil.groovy script.
  • Active Iron.io account.

Build a JAR file

  • Before building the JAR file containing the script and all other dependencies, you need to copy your .p12 APNS certificate to src/main/resources directory. Make sure to replace InputStream certificate = this.getClass().getResourceAsStream('/Sunrise.p12') with your certificate name.
  • Run gradle fatJar to build a JAR file which contains all dependencies used in the NotificationUtil.groovy script.
    • Optionally, you can use gradle runScript command to run the script locally for debugging purposes.

Create an IronWorker

  • Create a Dockerfile in the same directory where your newly created .jar file is located.
FROM iron/java

WORKDIR /app
ADD . /app

ENTRYPOINT ["java", "-jar", "notification-service.jar"]
  • Make sure to replace notification-service.jar with the proper name of the JAR file you have built.

  • Build your Docker image: docker build -t USERNAME/IMAGENAME:0.0.1 ., where USERNAME and IMAGENAME should match the name of your Docker hub username and the image name you want to assign to your notification service.

  • Push it to Docker Hub: docker push USERNAME/IMAGENAME:0.0.1.

  • Register your image with Iron: iron register USERNAME/IMAGENAME:0.0.1.

Create an IronMQ

  • Navigate to the MQ section of the Iron.io dashboard, and create a new unicast queue. For the subscriber URL, paste the Webhook URL of the IronWorker you created in the previous step.
  • Copy the Webhook URL of your IronMQ, and use it to subscribe to OrderCreated message.

Test

  • Login with a valid customer account on your Sunrise app instance, and make sure to allow push notifications. Customer's push token will be stored in a Customer's custom field.
  • Pick some product and make a reservation.
  • The Commercetools platform sends an OrderCreated message to the IronMQ you subscribed. The queue triggers the IronWorker, which retrieves customer's token from the Commercetools API, and sends the notification payload to the Apple's production notification server.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages