This section relates to the SAP S/4HANA Cloud event that is used to kick off the whole process, and is represented by the "EMITTER" block in the whiteboard diagram.
It can be found in the s4hana/event/
directory of this repository.
This component starts off the whole flow by emitting an event message to the "salesorder/created" topic on the instance of the Enterprise Messaging service.
It is a single Bash shell script emit
, supported by two helper libraries:
localutils
providing basic functions for logging, access token retrieval, and so onsettings
providing the actual names of instances, plans and service keys
The Emitter uses the Messaging API to publish a message to a topic on the bus provided by this project's Enterprise Messaging service instance. The specific API endpoint used is POST /messagingrest/v1/topics/{topic-name}/messages
.
The API call is authenticated with OAuth 2.0, whereby an access token is retrieved using details in the emdev
service instance's service key sk1
- the specifics which are from the settings
helper library.
The emit
Bash script uses some external commands, none of which are obscure, but some of which you may need to explicitly install:
uuidgen
(often found in theuuid-runtime
Linux package)curl
(see thecurl
home page)cf
(see the Install Guide)yq
(see theyq
home page)jq
(see thejq
home page)
You'll also need your SAP Enterprise Messaging service instance, as mentioned in the Message Bus section of the main repository README - follow the instructions to get it set up if you haven't already.
These instructions assume you've forked this repository (see the Download and Installation instructions) and cloned it locally.
The Emitter (the emit
script) is designed to be used from the command line, and expects a single parameter that is mandatory - the sales order number. This must be a sales order that exists in the Sandbox (S/4HANA mock system). Use your SANDBOX component to get a proxy running in front of the API Hub's mock service, and pick a valid sales order from the entityset. Assuming you go for a version of the proxy that you run locally, use the Sales Orders entityset at http://localhost:5000/sap/opu/odata/sap/API_SALES_ORDER_SRV/A_SalesOrder?$top=10 look for and pick a valid sales order number.
To use this Emitter:
- Move into this
s4hana/event/
directory - Make sure you're logged into CF and connected to your organization and space where you have your message bus
- Choose a sales order number (e.g. 1)
- Call the Emitter:
./emit <salesordernumber>
(e.g../emit 1
)
Invoking the emitter should look like this - there will be a couple of log messages produced:
$ ./emit 1
2020-10-07 12:50:56 Publishing sales order created event for 1
2020-10-07 12:50:56 Publish message to topic salesorder%2Fcreated
The
%2F
in the topic name is a URL encoded/
which is required because the Messaging API endpoint uses the topic name in the URL path. We could have theemit
script encode it, but that would mean an extra dependency on e.g. Python or an npm package for example, which is not worth it for this.