Spring boot actuator in console application - java

I have a console application using Spring. My application is connecting on a database and a JMS server.
I would like to know at the start up of my application, if it is well connected to the databse and the JMS.
I know that spring-boot-actuator do that efficiently and esealy, but it expose rest endpoints. I would like to know if it's possible to get Spring actuator's beans to get status informations, database and JMS status.
Is it possible ?
Thank you.

About your second question: Yes, springs actuators provide autoconfigured health indicators when they are found on classpath, see this list for more details (datasource and JMS is provided).
But you can also easily implement your own status informations by just implementing HealthIndicator and adding it as a #Component, more details can be found here.
You can expose them either with REST or with JMX, the exposure can be configured via application.properties, details can be found in the docs.

According to the documentation, endpoints can be exposed through HTTP or JMX. By default, Spring will expose actuator endpoints over JMX unless you configure it not to do so.
There is a table showing which endpoints are enabled in JMX and HTTP by default. If you want to enable them on HTTP, there are several security settings you should be aware of before exposing them (see docs link above).
In order to expose actuator endpoints over HTTP, you'll need to include the spring-starter-web start in your build.
Gradle:
compile('org.springframework.boot:spring-boot-starter-web')
Maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Again, check the security settings before doing this. Newer versions of boot should give you a good safe set of defaults.

Related

How to connect Kafka to legacy Spring

I am working on PoC of connecting legacy Spring application to Kafka. It is war application to be deployed in Tomcat, Spring version 4.3.12. Is there some library to make communication with Kafka almost as easy as with Spring Boot? I need just fundamental operations: sending message, listening for confirmation, receiving.
I have some experience with Spring Boot support as is provided in org.springframework.kafka:spring-kafka library. I am not sure how to efficiently adopt Kafka for legacy Spring - I'm thinking of using Kafka Java client which looks promising but as I am used to working at Spring Boot abstraction level I don't have clue how much code should I supply myself.
Web search is not much helpful in this case since it tends to show Spring Boot-related solutions. Migration of legacy application is considered too, I just need to have some idea how difficult each way is.
kafka-clients is all you need (from Maven Central, not Confluent). You could go a step further and look into Log4j2 Kafka bridge, then property files for that.
If you want to externalize config into regular Java .properties file, you can, or you can pull values from environment variables, if you follow 12-factor principles.
But if you don't already have Spring Boot dependencies, then I do not think adding them is worth it for only Kafka.
Also, the Spring-Kafka documentation covers how to configure your app without Boot.

Use embedded tomcat instead of netty with spring-gateway

I'm running this project: https://github.com/wdahlenburg/spring-gateway-demo
It uses netty by default, how can I change it to embedded tomcat instead? I've tried to modify the pom.xml and replaces spring-boot-starter-test with spring-boot-starter-tomcat, but it doesn't work.
Does anyone know how to do that?
I don't think it's possible, spring cloud gateway is build on top of reactive Spring WebFlux project and requires netty runtime, as stated in docs:
Spring Cloud Gateway requires the Netty runtime provided by Spring Boot and Spring Webflux. It does not work in a traditional Servlet Container or when built as a WAR.

Configuring Tracing for Datadog in Spring Boot application

I have a Spring Boot application and want to configure HTTP request tracing via dependency management without having to deal with setting up the java agent. Can anyone suggest the best way to do this?
I have the micrometer-registry-datadog dependency added to my pom and can see that there are a lot of undocumented com.datadoghq dependencies, but am unsure if any of these will solve my problem. I'm getting all of the JVM metrics, but want some more APM-type metrics now. Ideally I'd like to use the #Timed annotation and various others to get detailed metrics around API calls.

Monitor Endpoint using Spring Framework

I'm trying to find an out-of-the-box health check for my spring app. However, I can only find support for Spring Actuator. I'm not able to use Spring Actuator because my application is a Spring application and not a Spring boot app. Is there another library that I could make use of without having to write my own? I would ideally want an endpoint that could possibly give me data about whether my DB is up and possibly some of the java opts passed into that particular node

Spring Integration + Spring Boot Actuator Endpoints not showing up

I have been trying to learn more about Spring Boot and I would like to add the Actuator endpoints to my test Spring integration/Spring Boot project. However, it is a plain, CLI Spring integration project--there are no current REST or web services. I'd ideally like to add the ability to view the endpoints with a browser while the jar is running from the command line.
I have been looking through the tutorials and I'm not finding a lot on adding it to a regular project, rather than a web project.
I've added the dependencies (spring-boot-actuator), and can see the endpoints from the jconsole, but I never see a connection to a port on my system (using netstat) and never can navigate there.
Is there a tutorial or something that can show me how to have REST endpoints with a CLI project?
Thank you
newbo
You can monitor and manage your application using JMX instead. See the documentation here.
If you use IntelliJ IDEA, hit CTRL+Space in an application.properties file to see a lot of JMX properties ready for you, one of them being:
endpoints.jmx.enabled=true (true is the default value)
According to Spring Docs, in order to show the endpoint user need to have ACTUATOR role.If you need to access without having the role you need to add the following value to application.properties:
management.security.enabled=false
I think if it isn't a web project, no tomcat servlet will be embedded, therefor you wont be able to browse the actuator endpoints over http
Insert dependency spring-boot-starter-web into your project and it will probably work.

Categories