page_type | languages | products | name | description | ||
---|---|---|---|---|---|---|
sample |
|
|
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.
You will build an application with EventGrid to send EventGridEvent to a topic and use Service Bus Queue as Event Handler to receive.
- An Azure subscription
- JDK8 or later
- Maven
- An Event Grid Topic instance. If you don't have one, see Create a custom topic or a domain in Azure Event Grid.
- A Service Bus Queue instance. If you don't have one, see Create a queue in the Azure portal.
- You can also import the code straight into your IDE:
Use the following steps to create an event subscription to tell the Event Grid to send events to the Service Bus Queue:
- In the Azure portal, navigate to your Event Grid Topic instance.
- Select Event Subscriptions on the toolbar.
- On the Create Event Subscription page, enter a name value for the event subscription.
- For Endpoint Type, select Service Bus Queue.
- Choose Select an endpoint and then select the Service Bus Queue instance you created earlier.
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
In your terminal, run mvn clean spring-boot:run
.
mvn clean spring-boot:run
You can debug your sample by adding the saved output values to the tool's environment variables or the sample's application.yaml
file.
-
If your tool is
IDEA
, please refer to Debug your first Java application and add environment variables. -
If your tool is
ECLIPSE
, please refer to Debugging the Eclipse IDE for Java Developers and Eclipse Environment Variable Setup.
- Send a POST request
curl http://localhost:8080/publish
- Verify in your app’s logs that similar messages were posted:
New event received: '"FirstName: John, LastName: James"'
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.