Skip to content

Latest commit

 

History

History

spring-cloud-azure-sample-eventgrid

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
page_type languages products name description
sample
java
event-grid
Use EventGrid to send EventGridEvent and use Service Bus Queue as Event Handler to receive in a Spring Boot application.
This sample demonstrates how to use EventGrid to send EventGridEvent and use Service Bus Queue as Event Handler to receive in a Spring Boot application.

Use EventGrid to send EventGridEvent and use Service Bus Queue as Event Handler to receive in a Spring Boot application

This sample demonstrates how to use EventGrid to send EventGridEvent to a topic and use Service Bus Queue as Event Handler to receive.

What You Will Build

You will build an application with EventGrid to send EventGridEvent to a topic and use Service Bus Queue as Event Handler to receive.

What You Need

Subscribe to custom topic

Use the following steps to create an event subscription to tell the Event Grid to send events to the Service Bus Queue:

  1. In the Azure portal, navigate to your Event Grid Topic instance.
  2. Select Event Subscriptions on the toolbar.
  3. On the Create Event Subscription page, enter a name value for the event subscription.
  4. For Endpoint Type, select Service Bus Queue.
  5. Choose Select an endpoint and then select the Service Bus Queue instance you created earlier.

Configure the sample

spring:
  cloud:
    azure:
      eventgrid:
        endpoint: ${AZURE_EVENTGRID_ENDPOINT}
        key: ${AZURE_EVENTGRID_KEY}
      servicebus:
        connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING}
    function:
      definition: consume
    stream:
      bindings:
        consume-in-0:
          destination: ${AZURE_SERVICEBUS_QUEUE_NAME}
      servicebus:
        bindings:
          consume-in-0:
            consumer:
              auto-complete: false

Run Locally

Run the sample with Maven

In your terminal, run mvn clean spring-boot:run.

mvn clean spring-boot:run

Run the sample in IDEs

You can debug your sample by adding the saved output values to the tool's environment variables or the sample's application.yaml file.

Verify This Sample

  1. Send a POST request
curl http://localhost:8080/publish
  1. Verify in your app’s logs that similar messages were posted:
New event received: '"FirstName: John, LastName: James"'

Deploy to Azure Spring Apps

Now that you have the Spring Boot application running locally, it's time to move it to production. Azure Spring Apps makes it easy to deploy Spring Boot applications to Azure without any code changes. The service manages the infrastructure of Spring applications so developers can focus on their code. Azure Spring Apps provides lifecycle management using comprehensive monitoring and diagnostics, configuration management, service discovery, CI/CD integration, blue-green deployments, and more. To deploy your application to Azure Spring Apps, see Deploy your first application to Azure Spring Apps.