Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
page_type languages products description urlFragment
sample
java
azure-event-hubs
Azure Spring Cloud Sample project for Messaging Event Hubs client library
azure-spring-cloud-sample-messaging-eventhubs

Spring Cloud Azure Messaging Event Hubs Sample shared library for Java

Key concepts

This code sample demonstrates how to use AzureMessageListener.java to listen to events from Event Hubs.

Getting started

Running this sample will be charged by Azure. You can check the usage and bill at this link.

Create Azure resources

  1. Create Azure Event Hubs Namespace. Please note Basic tier is unsupported. After creating the Azure Event Hub, you can create your own Consumer Group or use the default $Default Consumer Group.

  2. Create Azure Event Hub and named event-hub-name.

  3. Create Azure Storage for checkpoint use.

Examples

  1. Update application.yaml.

    spring:
      cloud:
        azure:
          eventhub:
            connection-string: [eventhub-namespace-connection-string]
            checkpoint-storage-account: [checkpoint-storage-account]
            checkpoint-access-key: [checkpoint-access-key]
            checkpoint-container: [checkpoint-container]
  2. Run the mvn spring-boot:run in the root of the code sample to get the app running.

  3. Send a POST request

    $ curl -H "Content-type: application/json" -X POST http://localhost:8080/messages -d "{\"name\":\"hello\"}"
    
  4. Verify in your app’s logs that a similar message was posted:

    New message received: 'User{name='hello'}'
    
  5. Delete the resources on Azure Portal to avoid unexpected charges.

Troubleshooting

Next steps

Contributing