The project contains a coffee event handler function and one CloudEvents trigger. It handles the following event types:
com.sap.coffee.requiredreplying withcom.sap.coffee.producedcom.sap.coffee.producedreplying withcom.sap.coffee.consumedcom.sap.coffee.consumednot sending any reply
It carefully avoids sending the same events it receives as this would immediately lead to cyclic event (message) processing as in this example also the event source will be identical.
- Login to your
Cloud Foundry(CF) subaccount (usingcf login), - Login to your
FaaSinstance (usingxsfrt login), - Select an
SAP CP Enterprise Messaging(EM) service in your CF space.
Register your EM service in your FaaS environment. This will copy credentials from CF service key to a secure store inside FaaS. So far this is a manual step, an administrative one:
xfsrt-cli faas service register -s <EMInstanceServiceName> -b <EMInstanceServiceKey>Check the result by running.
xfsrt-cli faas service listThis command will list all registred services from your currently connected FaaS environment. Keep the console window open, you may want to double-check the data in the next step.
Create a deployment file.
It will apply data to your project while it is deployed, any secret, config or service data that you would not like to see inside git.
By default (if you just provide a file name) the file is created in sub-folder deploy which shall be ignored by git.
However, you can also specify an relative or absolute path anywhere on your machine.
Run inside the project directory:
faas-sdk init-values -y values.yamlThe file contains now all defaults from your project. Update the generated file:
- Provide your registered service
instance(uuid) - Provide your registered service
keyto use (key name) - You may want to double-check the output of command
xsfrt faas service list
Optionally run npm install for project devDependencies:
- to run a unit test for the function
- to run and debug the function locally
- to see code proposals and better understand the function parameters
Finally, deploy the project as usual. Run inside the project directory:
xfsrt-cli faas project deploy -y values.yamlTest the setup by sending sample events.
Use for example @sap/xb-msg-amqp-v100, it is already registered under devDependencies:
- Edit the file
./simulate/config.js, replacexxxby real credentials, further settings as needed - Run
npm installto get a local copy of the messaging client - Run
node ./node_modules/@sap/xb-msg-amqp-v100/examples/producer.js ../../../../simulate/config.js
The messaging client project contains more examples.
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file.