Git Product home page Git Product logo

notification-service-iron-worker's Introduction

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.

notification-service-iron-worker's People

Contributors

nikola-mladenovic avatar

Watchers

 avatar  avatar

Forkers

cneijenhuis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.