In one of our product we are using Spring ver. 4 framework. This product is hosted on Azure or AWS based on customer's preference. We would like to enable memcache for better performance.
Our desired configuration will be :
applicationContext.xml which will include cacheConfig.xml
This cacheConfig.xml (which may include a property file), should specify :
Is cache enabled OR disabled
Cache Provider.
I checked about spring simple memcache lib., which supports AWS Memcache.
We did couple of POC but all of them suggests change in code or use maven profile.
But not much luck.
I hope we are moving in right direction. Any comment/answer is most welcomed!
Thanks in advance.
You could disable caching with configuration property spring.cache.type=none. You could check out Memcached Spring Boot library which provides implementation for the Spring Cache Abstraction.
Related
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.
i have multiple spring boot apps running, and I'm creating a load balancing controller of some sort,
is there a way to find out which nodes are loaded more than others,
loaded meaning with running sessions, or requests.
You can use metric based monitoring for that. Depending on your context you can use the provided infrastructure of your cloud provider or hosting provider.
if you operate the nodes yourself you can use the opensource solution https://prometheus.io/ with node_exporter for machine metrics. Spring actuator provides prometheus metrics export with https://micrometer.io/ and if a metric, like number of sessions, is missing, you can easily extend it with your own metrics.
The Spring Boot Production Ready Features, aka Actuator, provides various metrics such as CPU usage, JVM stats, latencies, sessions, Spring MVC and WebFlux metrics, etc that are backed by Micrometer. The metrics can then be further integrated with various metrics systems such as JMX, DataDog, Prometheus, New Relic to name a few.
Please read the Micrometer: Spring Boot 2's new application metrics collector blog post and the Spring Boot Actuator Web API Documentation for more information.
I referred this tutorial to restrict certain ip in jboss and Spring Boot application.
http://www.mastertheboss.com/jboss-web/jbosswebserver/how-to-restrict-access-to-jboss-web-application-by-ip-or-host
But the tutorial is not complete. Where should I place those codes? Are there any other methods to do that?
If any one know any other methods please mention that here. Thanks in advance.
IMO the Valves mentioned in tutorial are the ways to customize tomcat embedded into the Jboss application. Note that this tutorial is really old - from 2014, probably JBoss has changed since then.
I remember back that times JBoss indeed included Tomcat inside to handle the web requests, so probably there was some kind of server.xml of tomcat.
Now, there are other ways:
Place the application behind some proxy that would restrict the access. Probably its the best approach if your environment supports that.
Use filters inside the application. You can create a web filter and register it in spring boot application regardless whether its a Jar with embedded server or WAR that you're planning to deploy on JBoss. This can be really flexible but on the other hand it includes some java coding and will consume some resources of your application. You can use this approach if you don't have spring security in your application and you don't want to introduce one, otherwise read (3).
Kind of paraphrase on 2 but used with spring security, that has the filtering facility built in: here is how you can do that. Note that besides the actual Java code used for implementation, 3 and 2 are pretty similar.
I'd approach this problem in the following way:
If the IP where connections are accepted is subject to change, I'd configure reverse proxy like nginx. This would mean you don't have to redeploy or restart your application if the IP address changes. Please see this guide for details on how to configure nginx: https://docs.nginx.com/nginx/admin-guide/security-controls/controlling-access-proxied-tcp/
Otherwise I'd refer to this article: https://access.redhat.com/solutions/18412 describing the following configuration in WEB-INF/jboss-web.xml:
<valve>
<class-name>org.apache.catalina.valves.RemoteAddrValve</class-name>
<param>
<param-name>allow</param-name>
<param-value>127.0.0.1,127.0.0.2</param-value>
</param>
</valve>
</jboss-web>
To me this concern should be handled on infrastructure level, not in application container. I would suggest to look into AWS Security Groups or equivalent concepts in other cloud providers.
If you are running it in private cloud/bare metal, you should investigate to restrict it on transport layer your infrastructure provides. There should be some possibility to configure firewall rules.
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.
I have a microservice developed using Spring Boot. The application is deployed in pivotal cloud foundry. I have set the logs levels in logback.xml which is part of the application. In order to change the log level , I have to update the logback.xml and rebuild / redeploy the app. Is there a better way to do this without having to redeploy the app? Is there a way to set log level as env variable in PCF?
I have not used logback so don't know much on it. But may be this thread can help - Set Logging Level in Spring Boot via Environment Variable
If you are using Spring Boot 1.5 or higher, and PCF 1.9 or higher you can change log levels from the Apps Manager without having to redeploy:
http://docs.pivotal.io/pivotalcf/1-9/console/using-actuators.html#manage-log-levels
Have you ever thought of externalizing your application configuration.... Pcf provides a service called config-server, which uses a git repo for maintaining your application configuration....
Using spring boot actuator, you can actually reload the updated configuration without actually doing redeploy/rebuild of your app.
This links should help you:
https://docs.pivotal.io/spring-cloud-services/1-5/common/config-server/index.html
https://spring.io/guides/gs/centralized-configuration/