A function is triggered by messages via AMQP trigger. It will return (echo) the received payload. According to the trigger configuration the function result will be sent as a new message using a given topic.
-
Make sure you are logged into your
Cloud Foundrysubaccount (usingcf login) -
A working instance of
Enterprise Messaging @SAP CPin a space of above mentioned subaccount. -
In your messaging instance, have three queues set up for:
i incoming messages (
inp01): which are consumed inside the functionii messages returned by the function (
out01)iii one where errors are directed to (
err01) -
Two topics for addressing:
iv messages produced by the function
v error messages
For this example we will register a service using the xfsrt-cli. This will simplify credential handling required for interacting with enterprise messaging inside the function:
Given the Enterprise Messaging service instance name and binding, run the following command:
xfsrt-cli faas service register -s <EMInstanceServiceName> -b <EMInstanceServiceKey>Create a deployment file to provide credentials, topics and queue names. Run inside the project directory:
faas-sdk init-values -y values.yamlUpdate the generated file:
- Make the following adjustments:
sourceAddressofinp01should point to the queue referred to in itargetAddressofout01should point to the topic referred to in ivtargetAddressoferr01should point to the topic referred to in v
Finally, deploy the project as usual. Run inside the project directory:
xfsrt-cli faas project deploy -y ./deploy/values.yamlTest the setup by sending a sample message to queue inp01. Because the amqp trigger amqp-echo is watching the queue, it will trigger the function amqp-echo which simply returns the received message payload. According to the configuration, the returned result is sent to the topic defined in out01. Check if everything is working correctly by verifying that the queue subscribed to the topic received the message. If the returned function result was an error, the message was be sent to topic err01 and the subscribed queue received it.
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.