In this blog post, I will look at the Solace Java Spring Boot project which provides a Spring Boot Starter for the Solace Java API with support for Spring auto-configuration. This is a follow up blog post to my first post on the topic of Spring Boot Starters which discussed JMS.
To recap, as part of Solace Labs, we’ve shared two projects to help other Solace users easily use Solace Messaging as the foundation for their Spring Boot microservices and applications:
Following the Solace Labs model, both projects are open source and we welcome contributions, suggestions and ideas from the community. We’ll keep updating these projects as we use them more ourselves, but already they are making our applications simpler. In this blog post, I’ll focus on the Solace Java Spring Boot Starter.
The Solace Java Spring Boot Starter and Auto-Configuration is very similar to the Solace JMS project in how it functions. It provides an auto-configuration implementation and Spring Boot starter POM for the Solace Java API. However, in this case your application is using the Solace Java API and therefore will contain Solace Java API calls in the application. Spring Boot Applications wishing to use Solace Java need to do the following things:
solace-java-spring-boot-starterdependency to the build.
To use Solace Messaging you need to add a single dependency pointing to the Solace Java Spring Boot Starter POM. This POM follows the Spring Boot Starter pattern and manages all other dependencies that your application needs to use the Solace Java API including the underlying Solace Java client library. For example, in Gradle:
or with Maven:
<dependency> <groupId>com.solace.labs.spring.boot</groupId> <artifactId>solace-java-spring-boot-starter</artifactId> <version>0.1.1</version> </dependency>
Updating your application to use the
To facilitate Spring dependency injection, this project introduces a new Solace Java API factory (
SpringJCSMPFactory). This class maintains the same interface as the Singleton
JCSMPFactory in the Solace Java API but it contains an associated
JCSMPProperties. This makes it easy to auto-wire this dependency in your code:
@Autowired private SpringJCSMPFactory solaceFactory;
Once you have the
SpringJCSMPFactory, it behaves just like the
JCSMPFactory and can be used to create JCSMPSessions. For example:
final JCSMPSession session = solaceFactory.createSession();
The final step is to provide the Solace Message Router configuration properties to your application. Spring Boot provides multiple ways to externalize your configuration properties of your application. In this example, I’ll use the
application.properties approach. But you could also use a Spring Configuration Server or whatever method is the norm in your environment.
application.properties, you need to add any details required by the Solace Java API to connect with the Solace Message Router. At a minimum you must specify the host. For example:
You can add other details like message-vpn, client-username, client-password by adding additional properties to application.properties. See the project readme for a full list of what is supported.
To see this all in action, checkout the sample which illustrates the points explained in the blog. And again, I think it’s easy to see why the Solace Spring Boot Starters combined with auto-configuration simplify Solace Messaging applications. Why don’t you try them out yourself in your application and see how it can help you?
If you’re new to the Solace Java API and would like more help getting up and running there are nice tutorials here: https://solace.com/get-started/java-tutorials/
Mark Spielman is a product leader with 15+ years of experience helping customers become event driven while building the products they need to become more successful. His current passion with Solace is making sure PubSub+ Cloud is the right choice for everyone looking to modernize their business and embrace event-driven transformation.
Throughout his career, he has had experience and interest in a wide range of topics including large-scale enterprise architecture, cloud platforms, developer engagement, SaaS, agile teams, cross-functional team building, operations and process improvements, product go-to-market, pricing strategies and data-driven product design.
Mark holds a B.A.Sc. in Computer Engineering from the University of Waterloo and always enjoys learning new things.[position] => [url] => https://solace.com/blog/author/markspielman/ ) )