Hear from Salesforce leaders on how to create and deploy Agentforce agents.
Contact Us 1-800-596-4880

Azure Event Hubs Connector 1.2 Examples - Mule 4

The following examples show several Mule flows for Azure Event Hubs Connector:

Before You Begin

  • Java 8, 11 or 17

  • Anypoint Studio 7.5 and later

  • Mule runtime engine (Mule) 4.3.0 and later

  • DataWeave

Create a Configuration File for a Connection

Create a configuration file that includes properties for a connection:

  1. Create a file named mule-app.properties in the /src/main/resources/ folder.

  2. In the mule-app.properties file, create a set of properties for the connection, similar to the ones that follow, replacing the bracketed text (including the brackets) with the correct values for your configuration:

    config.namespace = <namespace>
    	config.eventHuName = <eventHuName>
    	ad-config.tenantId = <tenantId>
    	ad-config.clientId = <clientId>
    	ad-config.ClientSecret = <ClientSecret>
    
    	sas-config.sharedAccessKeyName = <sharedAccessKeyName>
    	sas-config.sharedAccessKey = <sharedAccessKey>
    
    	bs-config.containerName = <containerName>
    	bs-config.accountName = <accountName>
    	bs-config.accountKey = <accountKey>

For more information about creating a properties file, refer to Configuring Property Placeholders.

Send a Single Event and Listen with EventHub Listener

This Mule flow sends a single event to an Event Hub. The result is displayed on the console.

This example uses the following operations:

  • HTTP Listener
    Accepts data from HTTP requests

  • Send a single event
    Sends a single event

  • Logger
    Shows that the event was published

  • Eventhub listener
    Reads events from an event hub in a namespace.

  • Logger
    Logs that the event was listened.

Studio flow for the Send a Single Event flow

XML for This Example

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule app:

Steps for Running This Example

  1. Verify that your connector is configured.

  2. Save the project.

  3. From a web browser, test the application by entering http://localhost:8081/eventsLeaving the Site.

Publish a Batch of Events and Listen with Partition Listener

This Mule flow sends multiple events simultaneously to an Event Hub. The result is displayed on the console.

This example uses the following operations:

  • HTTP Listener
    Accepts data from HTTP requests

  • Publish in bulk
    Sends a batch of events

  • Logger
    Shows that the events were published

  • Partition listener
    Reads events from a specific event hub partition in a namespace

  • Logger
    Logs twice the events listened.

Studio flow for the Publish a batch of Events flow

XML for This Example

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule app:

Steps for Running This Example

  1. Verify that your connector is configured.

  2. Save the project.

  3. From a web browser, test the application by entering http://localhost:8081/bulkLeaving the Site.

Send Single Event with Content Type

This Mule flow sends a single event to an Event Hub with content type as JSON.

Send Single Event with Content Type configuration in Studio

XML for This Example

Paste this code into the Studio XML editor to quickly load the flow for this example into your Mule app:

<flow name="Send-single-event-with-content-type" >
		<http:listener doc:name="events" config-ref="HTTP_Listener_config" path="/content"  />
		<azure-eventhubs:publish doc:name="Send a single event" config-ref="ActiveDirectory" partitionId="1" contentType="application/json">
			<azure-eventhubs:event ><![CDATA[#[{
 "body": write(payload, "application/json"),
}]]]></azure-eventhubs:event>
		</azure-eventhubs:publish>
		<logger level="INFO" doc:name="Logger" message="Event Published" />
	</flow>
xml
View on GitHub