For Micronaut Redis, is there a way to toggle whether or not caching is enabled using configuration properties? I see some other available caches have the ability to be enabled/disabled via configuration properties such as Ehcache.
Maybe bit late but:
Add in your pom.xml the following:
<dependency>
<groupId>io.micronaut.cache</groupId>
<artifactId>micronaut-cache-noop</artifactId>
</dependency>
Or gradle:
implementation("io.micronaut.cache:micronaut-cache-noop:2.3.0")
And in your application.yml (at this point you can user env variables)
noop-cache.enabled: true
Source: https://micronaut-projects.github.io/micronaut-cache/latest/guide/#noop
Related
I am trying to expose additional actuator endpoints in my Spring Boot 2.3 service. Attempting to add endpoints such as the prometheus and metrics for monitoring. But for some reason, the exposed endpoints are locked to the default loggers,health,info.
For some background, within the org, there is a parent Spring dependency which automatically brings all of the Spring essentials, as well as some generic code useful within the org. I use this dependency in many of my other projects and was able to expose these additional actuator endpoints successfully. However, in this project with multiple artifacts, I am unable to edit the default exposed actuator endpoints.
Printing the configurableEnvironment post init always shows the exposure property as follows
management.endpoints.web.exposure.include = loggers,health,info
This is after trying to override this property to an expanded list (loggers,health,info,Prometheus,metrics) using below methods:
Enabling specific endpoint via management.endpoint.metrics.enabled: true
Specifying these values in application.yaml
Passing this as a Command line arguement Dmanagement.endpoints.web.exposure.include=loggers,health,info,prometheus,metrics
Using mvn dependency:tree To exclude any transitive actuator dependencies
I don’t believe its due to the org’s parent pom, likely due to another dependency we are using. But due to the size of this project, it is quite hard to remove dependencies to test. Is there any way to track down where these properties are set. Or perhaps additional ways to force exposure of the additional endpoints I want?
——
Actuator config
management:
endpoints:
web:
exposure:
include: metrics,prometheus,info,health,logging
endpoint:
env:
enabled: true
metrics:
enabled: true
info:
enabled: true
health:
enabled: true
show-details: always
beans:
enabled: true
caches:
enabled: true
threaddump:
enabled: true
prometheus:
enabled: true
Actuator info
{"_links":{"self":{"href":"http://localhost:9050/actuator","templated":false},"health":{"href":"http://localhost:9050/actuator/health","templated":false},"health-path":{"href":"http://localhost:9050/actuator/health/{*path}","templated":true},"info":{"href":"http://localhost:9050/actuator/info","templated":false},"loggers":{"href":"http://localhost:9050/actuator/loggers","templated":false},"loggers-name":{"href":"http://localhost:9050/actuator/loggers/{name}","templated":true}}}
Your question lacks some background, like your pom.xml or build.gradle files and full application.yml config.
I will go through the basic steps, which you may have missed.
Firstly, please make sure that you've included the Prometheus dependency:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<scope>runtime</scope>
</dependency>
Also, don't forget that some metrics require the AOP dependency (like custome timers, for example):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
To enable the Prometheus metrics exposure, you should specify such configuration in your application.yml file (it seems like you did it correctly, but let's list it here for the full picture):
management:
endpoints:
web.exposure.include: health, info, prometheus
To verify that the Prometheus endpoints were exposed, please use the GET request to this URL: http://localhost:8080/actuator/prometheus
If those steps don't help you resolve your issue, please add more details to your question.
In spring-cloud projects, for some reason, need to put some properties into bootstrap.yml, so that to make the specific properties available earlier.
Then there are 2 config files: bootstrap.yml and application.yml.
Wondering is it ok to put everying into bootstrap.yml, and remove application.yml totally, to make it cleaner.
Since bootstramp.yml is just loaded earlier, it seems to be ok, right? Or, will this cause some issue in some case?
Basically idea is to get configurations from ConfigServer using Spring Cloud Config. But sometimes we need some configurations e.g. spring.application.name upfront so, I'm using those configurations in bootstrap.yml. Which generally overrides what's in an application.yml [if present]). Reference
Plus, yes you can put all your configurations in bootstrap.yml and it works simply fine. I've tested with more than four microservices.
Recently integrated Hazelcast in my existing spring mvc project. i want to disable multicast autodiscovery mechanism and want it through ip address. done the required changes in Hazelcast.xml and put it under resources i.e WEB-INF/classes but configuration not override.default configuration is active and multicast discovery mode not getting disabled. so let me know how to disable multicast discovery in spring mvc project?
If hazelcast.xml is on your classpath it should be automatically applied. You can check Hazelcast Reference Manual: Checking Configuration.
If it does not work for you, you can always:
explicitly define the configuration location with -Dhazelcast.config=<path-to-config>
use programmatic configuration
If nothing works for you, then please share a minimal sample project to reproduce the issue.
I'm setting up a (Spring boot 2) Spring cloud zuul/gateway and ran into timeout issues. After reading the official docs and checking a similar question, I'm not convinced about the proposed solution.
I use the following type of route configuration:
routes:
test-service:
path: /test-service/**
serviceId: test-service
which I believe to not be "url routes", so I think these properties do not apply:
zuul.host.connect-timeout-millis
zuul.host.connection-request-timeout-millis
zuul.host.socket-timeout-millis
I tried setting the properties below, but IntelliJ indicates these properties "do not exist". Is this a quirk in the IDE, or are these properties only present/active under certain circumstances?
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds= 11000
hystrix.command.default.execution.timeout.enabled=false
ribbon.ConnectTimeout= 10000
ribbon.ReadTimeout: 10000
E.g. see this screenshot from my bootstrap.yml, where it only suggests other properties:
Is Ribbon and hystrix present and active by default with this maven dependency?
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
If you want to configure timeout in Zuul you have two options ,
If you have configured Zuul to use service discovery, you need to configure these timeouts with the below Ribbon properties
ribbon.ReadTimeout
ribbon.SocketTimeout
If you have configured Zuul routes by specifying URLs then use below properties ,as per your configuration you need to use this one
zuul.host.connect-timeout-millis
zuul.host.socket-timeout-millis
Offical doc is here (Look into Zuul Timeouts section)
https://cloud.spring.io/spring-cloud-netflix/multi/multi__router_and_filter_zuul.html
Below will show how they work with Hystrix,
https://cloud.spring.io/spring-cloud-static/Edgware.SR3/single/spring-cloud.html#_service_discovery_configuration
Note : Properties are case sensitive
I tried setting the properties below, but IntelliJ indicates these
properties "do not exist". Is this a quirk in the IDE, or are these
properties only present/active under certain circumstances?
May be quirk in the IDE.We have official doc that says the property exits.
I have a spring boot application, it has a couple of #Entity classes and #RepositoryRestResource repositort interfaces for them. Now I want to write some tests, where I can check that I can add a new record into my database using those repositories, but I don't want to use my configured MySQL database for it, but instead I want to use some embedded db like H2. At the moment I have an application.properties file, which looks like this:
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=qwerty123
Question: How do I configure my app to use other db for tests? I have no xml in my project, everything is based on annotations. I tried to define #Configuration class with #Bean to create DataSource and then use it with #ContextConfiguration annotation on test class, but it says that it can't load context.
If you are using a Maven project, you can add a application.properties file into your src/test/resources, for example with the following content.
# Create DDL
spring.jpa.hibernate.ddl-auto=create
# H2 in local file system allowing other simultaneous connections
spring.datasource.url=jdbc:h2:~/test;AUTO_SERVER=TRUE
Also, you need to include H2 as dependency (pom.xml):
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.193</version>
</dependency>
Spring Boot provides 2 magic annotations related to JPA autoconfigs for tests: #DataJpaTest and #AutoConfigureTestDatabase.
The javadoc says:
By default, tests annotated with #DataJpaTest will use an embedded
in-memory database (replacing any explicit or usually auto-configured
DataSource). The #AutoConfigureTestDatabase annotation can be used to
override these settings.
If you are looking to load your full application configuration, but
use an embedded database, you should consider #SpringBootTest combined
with #AutoConfigureTestDatabase rather than this annotation.
So, the only thing you absolutely need is a dependency in your pom file:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
That's it. However, spring boot spec also has 2 useful caveats:
You need not provide any connection URLs. You need only include a
build dependency to the embedded database that you want to use.
If you are using this feature in your tests, you may notice that the
same database is reused by your whole test suite regardless of the
number of application contexts that you use. If you want to make sure
that each context has a separate embedded database, you should set
spring.datasource.generate-unique-name to true.
And another one:
If, for whatever reason, you do configure the connection URL for an
embedded database, take care to ensure that the database’s automatic
shutdown is disabled. If you use H2, you should use
DB_CLOSE_ON_EXIT=FALSE to do so. If you use HSQLDB, you should ensure
that shutdown=true is not used. Disabling the database’s automatic
shutdown lets Spring Boot control when the database is closed, thereby
ensuring that it happens once access to the database is no longer
needed.
That's almost all you need to know about Spring Boot and embedded DBs. I see absolutely no reason to use the scope of dependency other than test, unless you actually intentionally configure an embedded DB for your application runtime. Believe it or not H2 jar alone takes 1.8M inside your fat jar. In the world on granular microservices, serverless and lambda functions it does matter what you put inside your apps.
I would also recommend checking the options in #AutoConfigureTestDatabase. I use it with #SpringBootTest, but it can also be used with some other annotations, namely #DataJpaTest, both mentioned above:
You will need to use Spring Profiles - https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-set-active-spring-profiles
You will define an active profile using "spring.profiles.active = development" and then including H2 in your development profile.
The examples use YAML, but they work in standard properties files as well.