Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-10587716 DOCS-12915 Azure Event Hubs Messaging 1.0 #1747

Open
wants to merge 6 commits into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions azure-event-hubs-messaging/1.0/antora.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: azure-event-hubs-messaging-connector
version: '1.0'
display_version: 1.0 (Mule 4)
title: Azure Event Hubs Messaging Connector
nav:
- modules/ROOT/nav.adoc
asciidoc:
attributes:
page-component-desc: Enables you to access the Azure Event Hubs Messaging API.
page-connector-type: Connector
page-connector-level: Select
page-exchange-group-id: com.mulesoft.connectors
page-exchange-asset-id: mule4-azure-event-hubs-messaging-connector
page-runtime-version: 4.3.0
page-release-notes-page: release-notes::connector/azure-event-hubs-messaging-connector-release-notes-mule-4.adoc
page-vendor-name: microsoft
page-vendor-title: Microsoft
6 changes: 6 additions & 0 deletions azure-event-hubs-messaging/1.0/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.xref:index.adoc[Azure Event Hubs Messaging Connector]
* xref:index.adoc[About Azure Event Hubs Messaging Connector]
* xref:azure-event-hubs-messaging-connector-studio.adoc[Use Studio to Configure Azure Event Hubs Messaging Connector]
* xref:azure-event-hubs-messaging-connector-xml-maven.adoc[Azure Event Hubs Messaging Connector XML and Maven Support]
* xref:azure-event-hubs-messaging-connector-examples.adoc[Azure Event Hubs Messaging Connector Examples]
* xref:azure-event-hubs-messaging-connector-reference.adoc[Azure Event Hubs Messaging Connector Reference]
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
= Azure Event Hubs Messaging Connector 1.0 Examples - Mule 4

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

* <<send-single-event>>
* <<retrieve-event>>
* <<send-batch-events>>


== Prerequisites

* Java 8 or 11
* Anypoint Studio 7.5 and later
* Mule runtime engine (Mule) 4.3.0 and later
* DataWeave


[[send-single-event]]
== Send a Single Event

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
* *Transform Message* +
Outputs a String body and a random integer in Java
* *Send a single event* +
Sends a single event
* *Logger* +
Shows the HTTP response from the *Send a single event* operation

image::send-single-event.png[Studio Flow for the Send a Single Event operation]

=== XML for This Example

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

[source,xml,linenums]
----
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:azure-event-hubs-messaging="http://www.mulesoft.org/schema/mule/azure-event-hubs-messaging" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:munit="http://www.mulesoft.org/schema/mule/munit"
xmlns:munit-tools="http://www.mulesoft.org/schema/mule/munit-tools" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.mulesoft.org/schema/mule/munit-tools http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/azure-event-hubs-messaging http://www.mulesoft.org/schema/mule/azure-event-hubs-messaging/current/mule-azure-event-hubs-messaging.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<configuration-properties doc:name="Configuration properties" doc:id="acddcfe5-9f1d-42a6-a0d1-6dba5b820be1" file="mule-app.properties" />
<azure-event-hubs-messaging:config name="config" doc:name="Azure Event Hubs Messaging Config" doc:id="b1b57e8b-51b2-45ce-889f-90b1a5bb5773" >
<azure-event-hubs-messaging:connection namespace="${sas-config.namespace}" sharedAccessKeyName="${sas-config.sharedAccessKeyName}" sharedAccessKey="${sas-config.sharedAccessKey}" />
</azure-event-hubs-messaging:config>
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="e036784b-2130-4ddd-84e9-da282b4e9953" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="send-single-event-demo-flow" doc:id="8c564cb4-e0f7-498a-a4d3-c2ee61d9ff97" >
<http:listener doc:name="Listener" doc:id="48e0616c-588d-457b-8bfe-46749cda8fbd" path="/send" config-ref="HTTP_Listener_config"/>
<ee:transform doc:name="Event" doc:id="7d47a208-f08e-40f1-8a0c-738f0ea66251" >
<ee:message />
<ee:variables >
<ee:set-variable variableName="message" ><![CDATA[%dw 2.0
output application/java
---
"A STRING BODY " ++ randomInt(99)]]></ee:set-variable>
</ee:variables>
</ee:transform>
<azure-event-hubs-messaging:send-event eventHub="eventForSend" doc:name="Send a single event" doc:id="6256ec3e-fb52-4f19-8c06-ca36eff3afaf" config-ref="config" partitionId="3">
<azure-event-hubs-messaging:event-data ><![CDATA[#[vars.message]]]></azure-event-hubs-messaging:event-data>
</azure-event-hubs-messaging:send-event>
<logger level="INFO" doc:name="Logger" doc:id="36171050-05f4-425a-92a9-ffca7ef62789" />
</flow>
</mule>
----

=== Steps for Running This Example

. Verify that your connector is configured.
. Save the project.
. From a web browser, test the application by entering `http://localhost:8081/send`.


[[retrieve-event]]
== Retrieve an Event

This Mule flow retrieves an event from an Event Hub. You can update the message retention in the *Days* attribute. The result is displayed on the console.

This example uses the following operations:

* *HTTP Listener* +
Accepts data from HTTP requests
* *Transform Message* +
Outputs a String body and a random integer in Java
* *Send a single event* +
Sends a single event
* *Retrieve event* +
Retrieves an event from a specific event hub, consumer group, and partition
* *Logger* +
Shows the HTTP response from the *Send a single event* operation and the *Retrieve event* operation

image::retrieve-event.png[Studio Flow for the Retrieve Event operation]

=== XML for This Example

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

[source,xml,linenums]
----
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:azure-event-hubs-messaging="http://www.mulesoft.org/schema/mule/azure-event-hubs-messaging" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:munit="http://www.mulesoft.org/schema/mule/munit"
xmlns:munit-tools="http://www.mulesoft.org/schema/mule/munit-tools" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.mulesoft.org/schema/mule/munit-tools http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/azure-event-hubs-messaging http://www.mulesoft.org/schema/mule/azure-event-hubs-messaging/current/mule-azure-event-hubs-messaging.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<configuration-properties doc:name="Configuration properties" doc:id="acddcfe5-9f1d-42a6-a0d1-6dba5b820be1" file="mule-app.properties" />
<azure-event-hubs-messaging:config name="config" doc:name="Azure Event Hubs Messaging Config" doc:id="b1b57e8b-51b2-45ce-889f-90b1a5bb5773" >
<azure-event-hubs-messaging:connection namespace="${sas-config.namespace}" sharedAccessKeyName="${sas-config.sharedAccessKeyName}" sharedAccessKey="${sas-config.sharedAccessKey}" />
</azure-event-hubs-messaging:config>
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="e036784b-2130-4ddd-84e9-da282b4e9953" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="retrieve-event-demo-flow" doc:id="d0543470-daf8-4207-a7c0-492a9f359386" >
<http:listener doc:name="Listener" doc:id="208a2e8e-ac68-4d82-8545-c472c14dbb15" config-ref="HTTP_Listener_config" path="/retrieve"/>
<ee:transform doc:name="Transform Message" doc:id="550cec4d-78ed-4f4f-9772-0a94b9310819" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
"A STRING BODY " ++ randomInt(99)]]></ee:set-payload>
</ee:message>
</ee:transform>
<azure-event-hubs-messaging:send-event doc:name="Send a single event" doc:id="e0b12de6-6ffb-4673-802c-318c078a2cd4" config-ref="config" eventHub="testhub1222" partitionId="3">
<azure-event-hubs-messaging:event-data ><![CDATA[#[vars.message]]]></azure-event-hubs-messaging:event-data>
</azure-event-hubs-messaging:send-event>
<azure-event-hubs-messaging:retrieve-event doc:name="Retrieve event" doc:id="dba7f829-d3af-47b5-8a5c-2a20fedcba14" config-ref="config" eventHub="testhub1222" consumerGroup="testgroup" partitionId="3"/>
<logger level="INFO" doc:name="Logger" doc:id="de8c0ada-9aa8-4a76-a9b2-380dcb738573" />
</flow>
</mule>
----


=== Steps for Running This Example

. Verify that your connector is configured.
. Save the project.
. From a web browser, test the application by entering `http://localhost:8081/retrieve`.


[[send-batch-events]]
== Send a Batch of Events

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
* *Transform Message* +
Outputs multiple event bodies in Java
* *Send a batch of events* +
Sends a batch of events
* *Logger* +
Shows the HTTP response from the *Send a batch of events* operation

image::send-batch-events.png[Studio Flow for the Send a Batch of Events operation]

=== XML for This Example

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

[source,xml,linenums]
----
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:azure-event-hubs-messaging="http://www.mulesoft.org/schema/mule/azure-event-hubs-messaging" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:munit="http://www.mulesoft.org/schema/mule/munit"
xmlns:munit-tools="http://www.mulesoft.org/schema/mule/munit-tools" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.mulesoft.org/schema/mule/munit-tools http://www.mulesoft.org/schema/mule/munit-tools/current/mule-munit-tools.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/azure-event-hubs-messaging http://www.mulesoft.org/schema/mule/azure-event-hubs-messaging/current/mule-azure-event-hubs-messaging.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
<configuration-properties doc:name="Configuration properties" doc:id="acddcfe5-9f1d-42a6-a0d1-6dba5b820be1" file="mule-app.properties" />
<azure-event-hubs-messaging:config name="config" doc:name="Azure Event Hubs Messaging Config" doc:id="b1b57e8b-51b2-45ce-889f-90b1a5bb5773" >
<azure-event-hubs-messaging:connection namespace="${sas-config.namespace}" sharedAccessKeyName="${sas-config.sharedAccessKeyName}" sharedAccessKey="${sas-config.sharedAccessKey}" />
</azure-event-hubs-messaging:config>
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="e036784b-2130-4ddd-84e9-da282b4e9953" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="send-batch-events-demo-flow" doc:id="13a1c759-f4b1-4ce4-8ad3-c27a13148b00" >
<http:listener doc:name="Listener" doc:id="9306efae-c142-4620-af3b-ef1d93b4d626" config-ref="HTTP_Listener_config" path="/send_batch"/>
<ee:transform doc:name="Transform Message" doc:id="7037cad4-75b1-49ff-b369-b4e5626616f2" >
<ee:message >
</ee:message>
<ee:variables >
<ee:set-variable variableName="messages" ><![CDATA[%dw 2.0
output application/java
---
[{
body: "EVENT BODY 1" as Binary
},
{
body: "EVENT BODY 2" as Binary
},
{
body: "EVENT BODY 3" as Binary
}]]]></ee:set-variable>
</ee:variables>
</ee:transform>
<azure-event-hubs-messaging:send-events-batch doc:name="Send a batch of events" doc:id="7c45753e-1350-44e2-bb47-41ea4e2851aa" config-ref="config" eventHub="testhub1222" partitionId="3">
<azure-event-hubs-messaging:events-data ><![CDATA[#[vars.messages]]]></azure-event-hubs-messaging:events-data>
</azure-event-hubs-messaging:send-events-batch>
<logger level="INFO" doc:name="Logger" doc:id="8240ea89-c2ca-4f86-aa60-eaf3dde6f30c" />
</flow>
</mule>
----

=== Steps for Running This Example

. Verify that your connector is configured.
. Save the project.
. From a web browser, test the application by entering `http://localhost:8081/sendbatch`.


== See Also

* xref:connectors::introduction/introduction-to-anypoint-connectors.adoc[Introduction to Anypoint Connectors]
* https://help.mulesoft.com[MuleSoft Help Center]
Loading