The drawing shows me at a glance what would be spread over ten pages in a book. –Ivan Turgenev
In my recent post on Spring Integration: A hands on introduction, I have a diagram that illustrates a spring-integration
flow. I feel that such an illustration, gives us an awesome way to both document your flow and act as a dashboard to look thru when the spring-integration
project has been deployed to have near real-time stats on what is the load on a channel
, speed thru which your messages
are flowing thru, etc.
If you have used spring-integration using XML
config, the IDE
‘s would have this straight out of the box (Both in STS Eclipse & IntelliJ Idea).
Well, if you have gone thru that post, you would have noticed that we did not use XML
configs for the project, instead, we used the new and cool Java DSL
to define out flow. One downside of this I feel to this approach is that, since this whole Java DSL
way of defining the flow is fairly new and since our flows get generated dynamically when spring
builds up its context, we have no plugins for any IDE
‘s (At-least, none to my knowledge) that will give us this integration-graph
out of the box.
Fortunately, spring-integration
folks have not taken this lightly, we do have a way to visualize the flows when using spring-integration
with Java DSL
. Its not too straight-forward, but its not difficult either. Let’s today see how to visualize your integration-flows
using the project, Spring-Flo.
The link for that project will take you to the angular-1.x
branch of the project. That is because, currently the whole project is in the process of migration to angular 4/5
. Hence the stable version that we can use in the meantime is the one that is in the angular-1.x
branch. I will update this post if I find a newer stable version.
So, that being said, we need to use this external project in-order to visualize your flow, which is not too bad I feel (IMO, it is better than not having any means to visualize your flow). Also, I feel it would be giving more cleaner way to have a dashboard kind of view to see how are things going in real-time. So, I like the idea of having this as a different project.
Let’s right away jump into how to configure your spring-integration
project to use spring-flo
project. To begin with, this is how spring-flo
project will be able to generate the integration-graph
for you.
Your integration project will expose an endpoint (/integration
) which will give the near real-time stats of your integration components (Channels
, Service Activators
, etc.). This is just a plain JSON
response. The interesting part is that, spring-flo
project will latch on to this endpoint, and will provide you with an interesting visualization of the JSON
reply.
Dependencies needed:
- Make the project a web-based one, by including the
spring-boot-starter-web
. This will give you access to the /integration endpoint when your project boots up. - Include the
spring-integration-http
dependency to use the @EnableIntegrationGraphController on your application class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!– For exposing the /integration endpoint –> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-web</artifactId> | |
</dependency> | |
<!– For @EnableIntegrationGraphController annotation –> | |
<dependency> | |
<groupId>org.springframework.integration</groupId> | |
<artifactId>spring-integration-http</artifactId> | |
</dependency> |
Code configuration for your spring-integration
project:
- Add the
@EnableIntegrationGraphController
to your application class. - You need to allow access for
spring-flo
application to access the endpoint/integration
by specifying theallowedOrigins
on your annotation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SpringBootApplication | |
@EnableIntegrationGraphController(allowedOrigins = "http://localhost:8082") | |
public class Application { | |
public static void main(String[] args) { | |
SpringApplication.run(Application.class, args); | |
} | |
} |
Here in this example, I am planning to run the spring-flo
application on the same machine in the port 8082, so I’m just specifying that when I’m configuring my integration
project.
That’s all you have to do to your spring-integration
project.
Running spring-flo project:
- Clone the
spring-flo
project to your machine. - Checkout to the
angular-1.x
branch - Start your
spring-integration
project. - Run the
spring-flo/samples/spring-flo-si
project on 8082 since ourspring-integration
project will be expectingspring-flo
to be running on port 8082. - Go to
localhost:/8082
and click onLoad
button to load your integration flow graph.
It is not pretty straight-forward, but still, we have something to work on until spring
team would give a better solution in the future which I’m pretty confident they would. Until then, we have this web application that provides a wonderful way to watch our integration-flows
.