Monitor, receive, and send events with Azure Event Hubs and Azure Logic Apps

This article shows how you can monitor and manage events sent to Azure Event Hubs from inside a logic app with the Azure Event Hubs connector. That way, you can create logic apps that automate tasks and workflows for checking, sending, and receiving events from your Event Hub. For connector-specific technical information, see the Azure Event Hubs connector reference.

Prerequisites

Check permissions and get connection string

For your logic app to access your Event Hub, check your permissions and get the connection string for your Event Hubs namespace.

  1. Sign in to the Azure portal.

  2. Go to your Event Hubs namespace, not a specific Event Hub.

  3. On the namespace menu, under Settings, select Shared access policies. Under Claims, check that you have Manage permissions for that namespace.

    Manage permissions for your Event Hub namespace

  4. If you want to later manually enter your connection information, get the connection string for your Event Hubs namespace.

    1. Under Policy, choose RootManageSharedAccessKey.

    2. Find your primary key's connection string. Choose the copy button, and save the connection string for later use.

      Copy Event Hubs namespace connection string

      Tip

      To confirm whether your connection string is associated with your Event Hubs namespace or with a specific event hub, make sure the connection string doesn't have the EntityPath parameter. If you find this parameter, the connection string is for a specific Event Hub "entity" and is not the correct string to use with your logic app.

  5. Now continue with Add an Event Hubs trigger or Add an Event Hubs action.

Add Event Hubs trigger

In Azure Logic Apps, every logic app must start with a trigger, which fires when a specific event happens or when a specific condition is met. Each time the trigger fires, the Logic Apps engine creates a logic app instance and starts running your app's workflow.

This example shows how you can start a logic app workflow when new events are sent to your Event Hub.

  1. In the Azure portal or Visual Studio, create a blank logic app, which opens Logic Apps Designer. This example uses the Azure portal.

  2. In the search box, enter "event hubs" as your filter. From the triggers list, select this trigger: When events are available in Event Hub - Event Hubs

    Select trigger

  3. If you're prompted for connection details, create your Event Hubs connection now.

  4. In the trigger, provide information about the Event Hub that you want to monitor. For more properties, open the Add new parameter list. Selecting a parameter adds that property to the trigger card.

    Trigger properties

    Property Required Description
    Event Hub name Yes The name for the Event Hub that you want to monitor
    Content type No The event's content type. The default is application/octet-stream.
    Consumer group name No The name for the Event Hub consumer group to use for reading events. If not specified, the default consumer group is used.
    Maximum events count No The maximum number of events. The trigger returns between one and the number of events specified by this property.
    Interval Yes A positive integer that describes how often the workflow runs based on the frequency
    Frequency Yes The unit of time for the recurrence

    Additional properties

    Property Required Description
    Content schema No The JSON content schema for the events to read from the Event Hub. For example, if you specify the content schema, you can trigger the logic app for only those events that match the schema.
    Minimum partition key No Enter the minimum partition ID to read. By default, all partitions are read.
    Maximum partition key No Enter the maximum partition ID to read. By default, all partitions are read.
    Time zone No Applies only when you specify a start time because this trigger doesn't accept UTC offset. Select the time zone that you want to apply.

    For more information, see Create and run recurring tasks and workflows with Azure Logic Apps.

    Start time No Provide a start time in this format:

    YYYY-MM-DDThh:mm:ss if you select a time zone

    -or-

    YYYY-MM-DDThh:mm:ssZ if you don't select a time zone

    For more information, see Create and run recurring tasks and workflows with Azure Logic Apps.

  5. When you're done, on the designer toolbar, choose Save.

  6. Now continue adding one or more actions to your logic app for the tasks you want to perform with the trigger results.

    For example, to filter events based on a specific value, such as a category, you can add a condition so that the Send event - Event Hubs action sends only events that meet your condition.

Note

All Event Hub triggers are long-polling triggers, which means that when a trigger fires, the trigger processes all the events and then waits for 30 seconds for more events to appear in your Event Hub. If no events are received in 30 seconds, the trigger run is skipped. Otherwise, the trigger continues reading events until your Event Hub is empty. The next trigger poll happens based on the recurrence interval that you specify in the trigger's properties.

Add Event Hubs action

In Azure Logic Apps, an action is a step in your workflow that follows a trigger or another action. For this example, the logic app starts with an Event Hubs trigger that checks for new events in your Event Hub.

  1. In the Azure portal or Visual Studio, open your logic app in Logic Apps Designer. This example uses the Azure portal.

  2. Under the trigger or action, choose New step.

    To add an action between existing steps, move your mouse over the connecting arrow. Choose the plus sign (+) that appears, and then select Add an action.

  3. In the search box, enter "event hubs" as your filter. From the actions list, select this action: Send event - Event Hubs

    Select "Send event" action

  4. If you're prompted for connection details, create your Event Hubs connection now.

  5. In the action, provide information about the events that you want to send. For more properties, open the Add new parameter list. Selecting a parameter adds that property to the action card.

    Select Event Hub name and provide event content

    Property Required Description
    Event Hub name Yes The Event Hub where you want to send the event
    Content No The content for the event you want to send
    Properties No The app properties and values to send
    Partition key No The partition ID for where to send the event

    For example, you can send the output from your Event Hubs trigger to another Event Hub:

    Send event example

  6. When you're done, on the designer toolbar, choose Save.

Connect to your Event Hub

Before your logic app can access any service, you must create a connection between your logic app and that service. If you didn't previously create this connection, you're prompted for connection information when you add a trigger or action for that service to your logic app. The Logic Apps Designer provides an easy way for you to create this connection directly from your logic app.

  1. When you're prompted for connection information, provide these details:

    Property Required Value Description
    Connection Name Yes <connection-name> The name to create for your connection
    Event Hubs Namespace Yes <event-hubs-namespace> Select the Event Hubs namespace you want to use.

    For example:

    Create Event Hub connection

    To manually enter the connection string, choose Manually enter connection information. Learn how to find your connection string.

  2. Select the Event Hubs policy to use, if not already selected. Choose Create.

    Create Event Hub connection, part 2

  3. After you create your connection, continue with Add Event Hubs trigger or Add Event Hubs action.

Connector reference

For technical details, such as triggers, actions, and limits, as described by the connector's OpenAPI (formerly Swagger) file, see the connector's reference page.

Next steps

Learn about other Logic Apps connectors