Fabric API - Events

The Kafka and REST connections for an eventstream endpoint, every field of each.

An eventstream's custom endpoint accepts Kafka and REST clients, so the connections below are Zato's Kafka and REST connections configured for Fabric. The events page uses them in services. Eventhouses are queried with the Fabric connection's query_events.

Where the values come from

All values on this page come from the Details pane of the eventstream's custom endpoint, on the SAS Key Authentication page of its Kafka tab, whether the endpoint is a source (Zato sends) or a destination (Zato receives):

In FabricUsed as
Bootstrap serverThe Kafka address, <namespace>.servicebus.windows.net:9093
Topic nameThe Kafka topic, and the <topic name> in the REST address
Connection string-primary keyThe password of a Basic Auth definition for the PLAIN mechanism
Consumer groupThe Kafka channel's consumer group, on the Basic page of the destination

The namespace is the first part of the bootstrap server, up to .servicebus.windows.net.

Security definitions

Two kinds of definition sign a Kafka connection in, and both are created under Security in the Dashboard:

MechanismDefinitionFields
OAUTHBEARERBearer tokenUsername the application (client) ID, Password the client secret, Auth endpoint https://login.microsoftonline.com/<tenant ID>/oauth2/v2.0/token, Scopes https://<namespace>.servicebus.windows.net/.default
PLAINBasic AuthUsername $$ConnectionString, Password the connection string

The username is entered as $$ConnectionString because a value starting with a single $ names an environment variable, and doubling it gives the literal $ConnectionString.

An environment holds one Bearer token definition per client ID, so the Kafka scope and the REST scope each sign in as an app registration of their own, added to the workspace as a Contributor.

Kafka outgoing connection

Under Connections → Message queues → Kafka → Outgoing connections:

FieldValue
NameAny, used as self.out.kafka[name]
AddressThe bootstrap server
TopicThe topic name
SSLOn
SecurityThe Bearer token or Basic Auth definition
SASL mechanismOAUTHBEARER or PLAIN, matching the definition
outgoing_kafka:
  - name: Fabric Events
    address: <namespace>.servicebus.windows.net:9093
    topic: <topic name>
    security: Fabric Events Token
    sasl_mechanism: OAUTHBEARER
    ssl: true

A dict passed to send is JSON-encoded before it leaves:

event = {
    'event_type': 'admission',
    'location': 'Riverside',
    'admission_id': 'ADM-1041',
}

self.out.kafka['Fabric Events'].send(event)

Kafka channel

Under Connections → Message queues → Kafka → Channels:

FieldValue
NameAny
AddressThe bootstrap server
TopicThe topic name
Consumer groupThe group created for Zato on the destination
ServiceThe service to run for each event
SSLOn
SecurityThe Bearer token or Basic Auth definition
SASL mechanismOAUTHBEARER or PLAIN, matching the definition
channel_kafka:
  - name: Fabric Alerts
    address: <namespace>.servicebus.windows.net:9093
    topic: <topic name>
    group_id: zato
    service: fabric.notify-purchasing
    security: Fabric Events Token
    sasl_mechanism: OAUTHBEARER
    ssl: true

The eventstream sends events in batches, as a JSON list, which the service receives parsed in self.request.input:

for event in self.request.input:
    item_id = event['item_id']

REST alternative for sending

The same endpoint also takes events over HTTPS. Under Connections → REST → Outgoing connections:

FieldValue
Hosthttps://<namespace>.servicebus.windows.net
URL path/<topic name>/messages
Data formatJSON
SecurityA Bearer token definition with Scopes https://eventhubs.azure.net/.default

The body is a list of events, each wrapped in Body, sent with the endpoint's own content type:

body = json.dumps(event)
payload = [{'Body': body}]
headers = {'Content-Type': 'application/vnd.microsoft.servicebus.json'}

self.rest['Fabric Events REST'].post(payload, headers=headers)

See also

PageWhat it covers
Fabric eventsServices that send, receive and read events with these connections
Fabric API - Queriesquery_events, KQL queries against an eventhouse through the Fabric connection
Fabric API - ConnectionThe app registration the Kafka definition signs in as

Learn more