Event-driven Java with Spring Cloud Stream and Azure Event Hubs [Guest Post]

Engineering | Ben Wilcock | April 01, 2019 | ...

Asir Selvasingh | Principal PM Architect | Microsoft – Java on Azure

Spring Cloud Stream Binder for Azure Event Hubs is now generally available.

It is simple to build highly scalable event-driven Java apps using Spring Cloud Stream with Event Hubs, a fully managed, real-time data ingestion service on Azure that is resilient and reliable service for any situation; this includes emergencies, thanks to its geo-disaster recovery and geo-replication features.

Spring Cloud Stream provides a binder abstraction for popular message broker implementations. It provides a flexible programming model built on already established and familiar Spring idioms and best practices, including support for persistent pub/sub semantics, consumer groups, and stateful partitions. Now, developers can use the same patterns for building Java apps with Event Hubs.

Diagram showing Spring Apps inputting to Azure Event Hubs and outputting to other Spring apps, using the Azure event hubs binder and channels.

Getting Started

Check out this tutorial and build a Java-based Spring Cloud Stream Binder application using the Spring Boot Initializer with Azure Event Hubs. Go to the Azure portal and create a new Event Hubs namespace. Add the following Maven dependency into your Java project.


Publish messages

Use @EnableBinding(Source.class) to annotate a source class and publish messages to Event Hubs with Spring Cloud Stream patterns. You can customize the output channel for the Source with configurations.

  • Destination: specify which Event Hub to connect with the output channel
  • Sync/Async: specify the mode to produce the messages

Subscribe to messages

Use @EnableBinding(Sink.class) to annotate a sink class and consume messages from Event Hubs. You can also customize the input channel with configurations. Please refer to this tutorial for the full list.

  • Destination: specify an Event Hub to bind with the input channel
  • Customer Group: specify a Consumer Group to receive messages

Try building event-driven Java apps using Spring Cloud Stream Binder for Event Hubs

Try out a Java app using Spring Cloud Stream Binder on Azure Event Hubs and let us know what you think via e-mail or comments below.

Additional Resources

About the Author

Asir started his software engineering career in the early days of Java, in 1995, and built enterprise products, applications and open source projects for many years. Now, he is a Principal PM Architect at Microsoft focusing on a full gamut of services and tools for developers to build and scale Java workloads on Azure. He works closely with the community, delivering sessions at Java conferences and fostering strategic relations that enrich the Java ecosystem.

In his free-time, Asir loves to tinker with Java apps on Azure, which serves as a creative outlet from his day job. He’s passionate about cooking and photography and enjoys quality family time traveling the world.

Get the Spring newsletter

Thank you for your interest. Someone will get back to you shortly.

Get ahead

VMware offers training and certification to turbo-charge your progress.

Learn more

Get support

Spring Runtime offers support and binaries for OpenJDK™, Spring, and Apache Tomcat® in one simple subscription.

Learn more

Upcoming events

Check out all the upcoming events in the Spring community.

View all