This document describes how to publish events through the Business Eventing Toolkit for SAP.
Publish events programmatically to configured Google Cloud targets
The target service is derived based on the configured target Google Cloud services. For information about how to configure target Google Cloud services, see Configure target Google Cloud services.
The following code snippet shows how to publish event data to configured targets:
/goog/cl_event_publisher=>publish_event(
EXPORTING
iv_event_key = 'EVENT_KEY'
it_data = VALUE /goog/cl_publisher_base=>tt_messages( ( data = 'Hello World!' ) )
IMPORTING
et_output = DATA(lt_output)
et_return = DATA(lt_return)
).
Replace EVENT_KEY
with the event key configured for publishing events to your target Google Cloud services.
To send an event as a CloudEvent, you can configure the Cloud Event Default Attribute Key and attach this key to your Event Key when configuring the target Google Cloud services. The Business Eventing Toolkit for SAP then picks up the default attribute values for the CloudEvent.
Publish API requests programmatically as CloudEvents with default values
The following code snippet shows how to publish an HTTP API request as a CloudEvent with default values:
lo_api_client->encode_as_cloud_event(
EXPORTING
iv_ce_key = 'CLOUD_EVENT_ATTRIBUTE_KEY'
).
Replace CLOUD_EVENT_ATTRIBUTE_KEY
with the Cloud Event Default Attribute Key configured in the Configure CloudEvent attributes section.
Publish API requests programmatically as CloudEvents
To override the default values defined in the configuration table when you publish
a business event as a CloudEvent programmatically, you can pass specific values
for CloudEvent attributes using the ENCODE_AS_CLOUD_EVENT
method.
The following code snippet shows how to override the default values when encoding an HTTP request as a CloudEvent:
lo_api_client->encode_as_cloud_event(
EXPORTING
"mandatory attributes
iv_source = 'SAP'
iv_type = 'ce.structured-ce'
" add optional attributes
iv_subject = 'test'
" extension attributes -> key,value
it_extension_attr = VALUE #( ( name = 'my_ext_attr1' value = 'my_ext_value1')
( name = 'my_ext_attr2' value = 'my_ext_value2' ) )
iv_encoding = /goog/if_ce_spec_version=>c_ce_encoding-binary
).
Explore the following to publish your SAP events:
- Publish events to Pub/Sub
- Publish events to Cloud Run functions
- Publish events to Firebase Cloud Messaging
- Publish events to Integration Connectors