Can I completely disable bus functionality in Spring Cloud? - spring

Currently I have the following configuration for local development. In our cloud environment where we deploy to GCP, obviously some of these properties are then activated because they're needed. We use Spring Cloud Bus specifically to send events between applications, e.g. to replace properties.
spring:
cloud:
gcp:
config.enabled: false
core.enabled: false
logging.enabled: false
trace.enabled: false
pubsub.enabled: false
bus:
enabled: false
When doing this, things aren't fully disabled. Some components are still loaded and attempt bean creation. Several components in spring-cloud-stream are fully loaded. I even get some warnings:
2022-05-24 13:21:46.744 WARN [ restartedMain] onConfiguration$FunctionBindingRegistrar : You have defined function definition that does not exist: busConsumer
2022-05-24 13:21:48.864 INFO [ restartedMain] o.s.c.s.binder.DefaultBinderFactory : Creating binder: pubsub
As a result, it seems like not all components are properly disabled. I also found an old issue indicating that this behavior is expected. We actually ran into issue with some missing beans due to conflict with other another library (coffee-boots), because not all components were disabled properly and still attempted to load some beans.
Is there any way to properly disable all functionality for local development?
When debugging, I stumbled upon spring.cloud.stream.function.autodetect=false, but that did not help - for example if any of your beans implement java.lang.Function, spring-cloud-stream-function will interact with it whether it is disabled or not.

Related

spring.config.import doesn't accept configserver option when in yaml

I have a bunch of services and recently migrated to new Spring Boot/Cloud. All but one works ok. The one complains like this:
***************************
APPLICATION FAILED TO START
***************************
Description:
Config data location 'configserver:http://localhost:8888/' does not exist
Action:
Check that the value 'configserver:http://localhost:8888/' at class path resource [application.yaml] - 5:13 is correct, or prefix it with 'optional:'
Making it optional makes service to completely skip remote configuration. Other services tells
Fetching config from server at : http://localhost:8888/
but this one misses it completely.
I've checked dependencies, they looks ok, tried to use latest spring-cloud-starter-config 3.0.5 but didn't change anything.
application.yaml looks like this:
spring:
application:
name: some-service
config:
import: "configserver:http://localhost:8888/"
cloud:
config:
fail-fast: true
retry:
max-attempts: 5000
initial-interval: 1500
multiplier: 1.5
All services has exactly the same config, just different names.
I have also another service which had similar problem, and switching from application.yaml to application.properties has fixed the problem. I don't like this solution, that's why I'm asking for help here. I suppose I miss some dependency or it has different version. I've even found similar problem, but no solution is visible: https://github.com/spring-cloud/spring-cloud-config/issues/1933
Edit: I've switched from yaml to properties format and it's working ok. Why yaml is not working?
So the problem was excessive application.properties in one of attached library. After removing this properties everything is working as expected.
Probably something in Spring Boot doesn't like such additional properties.

Spring Cloud Embedded Config Server with native repository

I have a working spring boot application and I am trying to remove some properties from application.yaml file and read them from an embedded config server in the same app. At the moment, I am trying to read properties from file system through "native" profile type, and I am planning to later replace this with S3. Also, I am trying to read the configuration directly from backend repository as explained here https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#_embedding_the_config_server , rather than connecting through an endpoint.
If you want to read the configuration for an application directly from
the backend repository (instead of from the config server), you
basically want an embedded config server with no endpoints. You can
switch off the endpoints entirely by not using the #EnableConfigServer
annotation (set spring.cloud.config.server.bootstrap=true).
I have introduced following changes to my existing application to achieve this.
Added following dependencies to pom.xml
spring-cloud-starter-config
spring-cloud-config-server
spring-cloud-config-client
application-dev.yaml
spring:
could:
bootstrap:
enabled: true
bootstrap.yaml
spring:
profiles:
active: composite
cloud:
config:
server:
composite:
- type: native
search-locations: file:C:\\Users\\chamila\\config-test\\config
# bootstrap: true
The required properties are saved in a different application-dev.yaml file at the above file path. I have not used #EnableConfigServer annotation from my app class, as I want connect directly without the endpoint.
However, still my program is failing to read the properties from the config-server. I tried setting spring.cloud.config.server.bootstrap=true and spring.cloud.bootstrap.enabled=true from both application-dev.yaml and bootstrap.yaml, but it didn't work?
Any idea what I am missing? I note that I never specified how to connect to the config-server in my application-dev.yaml file also. Is that an issue?
Any help is highly appreciated.
I created a sample project of an embedded Configuration Server which uses a custom repository:
https://github.com/taxone/embedded-config-server
The initial problem was that the custom EnvironmentRepository was not available via bootstrap, as described in this issue.
I followed https://cloud.spring.io/spring-cloud-config/reference/html/#_embedding_the_config_server and achieved the expected result.
Add spring-cloud-starter-bootstrap to your dependencies as suggested in https://github.com/taxone/embedded-config-server.
Make sure that composite profile is active when you start the app.
Verify that your native configuration is added by finding a log message from NativeEnvironmentRepository during startup.
(Optional) Remove spring.cloud.bootstrap.enabled from application-dev.yaml.
(Optional) Remove spring-cloud-config-client dependency as it is included in both spring-cloud-starter-config and
spring-cloud-config-server.
(Further steps) Use #RefreshScope on a spring bean to achieve dynamic properties. Requires POST actuator/refresh.

Disable specific bean types from cloud foundry java-buildpack-auto-reconfiguration

I have the problem that im my company there is a workaround for using the db2 broker in cloud foundry. To get this work you have to disable the java-buildpack-auto-reconfiguration in your application with this property:
JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'
Otherwise you get this error:
DB2 SQL Error: SQLCODE=-142, SQLSTATE=42612, SQLERRMC=null
In the git project (https://github.com/cloudfoundry/java-buildpack-auto-reconfiguration) I read that this property disables re-writes of bean definitions of various types (javax.sql.DataSource, org.springframework.data.mongodb.MongoDbFactory, org.springframework.amqp.rabbit.connection.ConnectionFactory, ...) to connect automatically with services bound to the application. In our application we use MongoDB as well as DB2. Therefore I am worried about that with this configuration I disable something that I do not want to disable for MongoDB.
I hope this will get fixed soon that I do not need this configuration. But for now is it possible to only disable the reconfiguration for specific bean types (in my case "javax.sql.DataSource")?

"Open Live Beans Graph" is disabled

I have a Spring MVC project inside of Spring Tools Suite that uses Java based Spring configuration and Gradle.
- I've added the Spring Project Nature.
- I'm not using #ComponentScan, I define all beans explicitly.
- I have "Auto detection for annotated Java Spring configuration files" turned on.
Why is "Open Live Beans Graph" disabled (greyed out) in my Project/Spring Tools menu?
Thanks!
The live beans graph is showing the beans that are being created in the running application, so you need to run the app (in your case I guess you run that in tc Server), and open the live beans graph view for that application. You can do that from the tc Server editor, there is a section for live bean graphs being available (and you can enable the feature in general).
If you do not run the app in tc Server, you have to set a property in order to enable this feature in your running application and connect to that application from the live beans graph view manually.
Hope that helps!
Spring MVC may not be enough to get it to work.
https://docs.spring.io/sts/nan/v310/NewAndNoteworthy.html says:
To allow proper communication, servers must be configured to enable
JMX and must also be given the VM argument
'-Dspring.liveBeansView.mbeanDomain' in order for the Spring Framework
to produce the data required to build up the graph.
I think the easiest is to get it to run in Spring Boot.
https://codecentric.github.io/spring-boot-admin/1.4.3/#jmx-bean-management

glassfish 3.1.2 monitoring EJB container, bean-methods

the glassfish application server provides a nice monitoring REST interface.
To use it u can enable several monitorable items in the admin console, for example the EJB container. The documentation says, you can retreive EJB-statistics for every deployed application.
If you request a URL like localhost:4848/monitoring/domain1/server/applications/APPNAME/EJBNAME you will get statistics for a given EJB of the application.
Further, there is a possibility to look more deeply into each bean-method of the ejb, for example the executiontime, about which the documentation says:
"Time, in milliseconds, spent executing the method for the last successful/unsuccessful attempt to run the operation. This is collected for stateless and stateful session beans and entity beans if monitoring is enabled on the EJB container."
The problem now is, monitoring is enabled on the EJB-container (Level set to HIGH), but nothing is sampled in any bean-method in any EJB in any deployed application.
Is there something special to do in the bean and/or the glassfish ?
Thanks in advance for help,
Chris
EDIT:
Ok, I noticed something more about that behaviour:
In the server log you get a log message for each deployed EJB like that:
INFO: EJB5181:Portable JNDI names for EJB DataFetcher // ...
If I set the ejb-container monitoring level to HIGH (which is what I want to do), I get the following warning for each deployed EJB, regardless which app I deploy:
WARNING: MNTG0201:Flashlight listener registration failed for listener class : com.sun.ejb.monitoring.stats.StatelessSessionBeanStatsProvider , will retry later
I googled the warning but none of the resulst really help me enabling EJB monitoring...
This seems to be a Bug in Glassfish.
EJB Monitoring is currently not working in 3.1.2.
JIRA issue is already raised: http://java.net/jira/browse/GLASSFISH-19677
There is nothing "special" to do.
http://docs.oracle.com/cd/E18930_01/html/821-2431/abeea.html
For me it seems as if you probably enabled the monitoring option on the wrong configuration. Please double check.
To get rid of this message you can disable the monitoring on ejb container option below in the image
From Monitor Data--->Configure monitoring--->make ejb container log off

Resources