📢 Please be aware that this sample is no longer maintained and the repository is archived
As an alternative, we recommend to use the samples based on the SAP BTP Developer Guide.
The Gamified Application is a sample Node.js application that showcases how to use and implement WebSockets, SAP BTP, serverless runtime, SAP Open Connectors and others. This application runs on the SAP BTP, Cloud Foundry environment, and the SAP BTP, Kyma environment. The current scope of the application is to demonstrate the capabilities of the SAP Event Mesh service for creating service instances, queues, subscriptions for these queue, and sending and consuming the messages through APIs.
The Gamified Application is developed using Node.js and runs on the SAP Business Technology Platform (SAP BTP). It consumes services in SAP BTP like SAP Event Mesh and SAP Open Connectors. The events generated in the gaming backend are inserted into a queue in the Event Mesh service. The application consumes these events to calculate the game result, and the serverless function publishes the result on Twitter via the SAP Open Connectors.
- Global account in SAP Business Technology Platform
The application requires below set of SAP Business Technology Platform entitlements and quota:
Service | Plan | Number of Instances |
---|---|---|
Event Mesh | default | 1 |
Kyma runtime | 1 | |
Open Connectors | 1 | |
SAP HANA Cloud | 1 | |
SAP HANA Schemas & HDI Containers | hdi-shared | 1 |
For more information, see Configure Entitlements and Quotas for Subaccounts.
- Clone the repository.
- Open a command prompt and run the command
npm install
.
- Enable Kyma Runtime environment.
- Subscribe to the SAP Open Connectors from service market place in SAP BTP Subaccount.
- Choose go to application to create a Twitter open connector instance. See Serverless Extensions – Part 2: Configure SAP Cloud Platform Open Connectors to connect to Whatsapp and Twitter
- Copy the Twitter Authorization Token and save it for later.
- Subscribe to the SAP Event Mesh service. See Subscribe to Event Mesh.
- Create SAP HANA Schemas & HDI Containers hdi-shared instance
- Open terminal and perform the below commands:
- Create Hana cloud instance if you do not have one in your SAP BTP environment. You can find a tutorial for creating a HANA Cloud instance at SAP Help Portal.
cf create-service hana-cloud hana my_hana_db -c '{"data":{"edition":"cloud","memory":30,"systempassword":""}}'
- Retrieve the GUID of the Hana cloud instance (if you have mulitple Hana cloud instances)
cf service <hana cloud instance name> --guid
- create instance with hdi-shared plan
cf create-service hana hdi-shared BusinessPartnerValidation-db -c '{"database_id" :"<guid>"}'
- Copy service key
cf create-service-key SERVICE_INSTANCE SERVICE_KEY
-
Generate a URL for the game by replacing host name and kyma API endpoint in the below URL:
- "https://{host name}.{kyma API End Point}"
- Make sure the host name and the apphost in values.yaml in line 34, both are same.
-
Copy the generated URL and replace with the URL in src/config.js:
-
Replace the Twitter API Endpoint URL in line 2 of serverless/twitter/handler.js.
-
Replace the Twitter Authorization token(copied in SAP BTP setup step 5) in line 3 of serverless/twitter/handler.js.
-
Replace the HANA hdi-shared credentials(copied in SAP BTP setup step 7) in:
- hanaConfig in Line 4 of src/config.js
- hanaConfig in Line 8 of serverless/queue/handler.js
-
Run the command
node src/db.js
to create data model in HANA db. -
Delete the file
src/db.js
or comment all the content ofsrc/db.js
. -
Build Docker Image:
docker build --pull --rm -f "Dockerfile" -t {username}/{appname}:latest "."
docker push {username}/{appname}:latest
-
Update helmcharts/values.yaml:
- Change variable values:
- namespace: replace with your Kyma runtime namespace.
- Image: replace with your Docker image name.
- apphost: replace hostname with the name that we chose for app URL.
- giturl: upload the game in a git repositiory and paste the link in this variable.
- Replace git username and password with your git username and passowrd in base64.
- Change variable values:
-
Deploy The application via helm:
- Open directory of helmcharts.
- Use the command
helm install {deployment name} ./ -n={namespace}
to push the application.
- Create New Room:
- Join The Room:
- Start The Game:
- Once sufficient players have joined the Room, the admin can start the game by clicking on the
Start Game
button. - If the admin wants to share the live gameBoard, the admin can click on the
gameBoard
button before starting the game.
- Once sufficient players have joined the Room, the admin can start the game by clicking on the
- Play The Game:
Copyright (c) 2021 SAP SE or an SAP affiliate company. All rights reserved. This project is licensed under the Apache Software License, version 2.0 except as noted otherwise in the LICENSE file.