I use to work on spring boot and when i need to externalize the config values. I genrally create a application.yml
SUD:
BASEPATH: ${SUD_SERVICE_BASE_PATH:https://origin-sud.com}
MCS_BASEPATH: ${SUD_SERVICE_MCS_BASE_PATH:https://sud.com/}
MCS_TOKEN: ${SUD_SERVICE_MCS_TOKEN:a2341b8b-4ca5-4513-8c52-gf267bihbh}
MCS_SUBSCRIPTION_ENDPOINT: ${SUD_SERVICE_MCS_SUBSCRIPTION_ENDPOINT:/v1/manag}
HOST: ${SUD_SERVICE_HOST:sud.com}
Now The values like
SUD_SERVICE_BASE_PATH
SUD_SERVICE_MCS_BASE_PATH
SUD_SERVICE_MCS_TOKEN
SUD_SERVICE_MCS_SUBSCRIPTION_ENDPOINT
SUD_SERVICE_HOST
Are getting data from EKS config map. If the values are not present, we get to the default values.
https://origin-sud.com
https://sud.com
To access it in the spring boot code. We do the below operation. It get the data from EKS config if present or default to default values.
#GetMapping("${SUD.MCS_SUBSCRIPTION_ENDPOINT}")
Now i want to do that same in vert.x.
I have read vert.c blog but i couldn't find a way to do it.
The only way i found out it to get the values like
String host = System.getenv.getOrDefault("SUD_SERVICE_BASE_PATH", https://origin-sud.com);
String port = System.getenv.getOrDefault("SUD_SERVICE_MCS_BASE_PATH", https://sud.com/);
I want to do something similar to spring boot , instead of calling the System.getenv.getOrDefault. I want to do it in config.
Appreciate the help provided.
Vert.x Core does not provide such a solution.
You need to add the Vert.x Config module, which is able to merge values coming from different sources (system properties, environment variables, config files... and more)
Related
I have a #FeignClient interface:
#FeignClient(name="${some.service.id}", url="${some.service.url}")
public interface SomeInterface {
...
}
My question is- how can I direct feign to use one of the two properties (name/url)? I left the url property empty in the production properties file, but it seems as if it always uses the url property.
So eventually I found a suitable solution here:
Define different Feign client implementations based on environment
Although I wanted to solve this using only one feign client with configuration and profiles, I didn't find a way to do it. This solution is based on creating two different feign clients, each will be used in the right profile.
I am developing a project with spring boot and SQL server. Almost all of my strings are persian and needs to be stored as utf-8. but for every string field I'm forced to use #Nationalized annotation on every string field to force jpa to create that column as nvarchar. Otherwise the string won't persist correctly. Is there a more convenient way to do this?
According to the Hibernate documentation this is possible:
If your application and database use nationalization, you may instead
want to enable nationalized character data as the default.
You can do this via the hibernate.use_nationalized_character_data
setting or by calling
MetadataBuilder#enableGlobalNationalizedCharacterDataSupport during
bootstrap.
Source: https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#basic-nationalized
In Spring Boot application.properties you have to set:
spring.jpa.properties.hibernate.use_nationalized_character_data =true
I'm using spring integration to store data in a mongo database. I'm using the java classes (MongoDbStoringMessageHandler), not the xml configuration and I can't find the way to get the results when adding some data in the database...
Is it possible ? How ?
The MongoDbStoringMessageHandler is a one-way component and it doesn't return anything.
Consider to use a MongoDbOutboundGateway instead with the CollectionCallback injected where you can perform an updateMany() and get UpdateResult as a reply from this gateway.
See more info in the Reference Manual: https://docs.spring.io/spring-integration/reference/html/mongodb.html#mongodb-outbound-gateway
UPDATE
but I don't know what parameter to put for the function to insert the Message payload.... Since there is no reference of the message in the ServiceActivator
Oh! I see. That a bug. We can't get access to the message from that context. Please, raise a JIRA on the matter: https://jira.spring.io/projects/INT/
Meanwhile as a workaround I suggest you ti write a custom POJO with injected MongoOperations and ther you can build any possible logic against a requestMessage.
The JIRA is here: https://jira.spring.io/browse/INT-4570
Let say I have these configurations in my xml,
<int-sftp:outbound-channel-adapter id="sftpOutbound"
channel="sftpChannel"
auto-create-directory="true"
remote-directory="/path/to/remote/directory/"
session-factory="cachingSessionFactory">
<int-sftp:request-handler-advice-chain>
<int:retry-advice />
</int-sftp:request-handler-advice-chain>
</int-sftp:outbound-channel-adapter>
How can I retrieve the attributes i.e, remote-directory in Java class ?
I tried to use context.getBean('sftpOutbound') but it returns EventDrivenConsumer class which doesn't have methods to get the configurations.
I'm using spring-integration-sftp v 4.0.0.
I am actually more concerned with why you wan to access it. I mean the remote directory and other attributes will come with the headers of each message, so you will have access to it at the Message level, but not at the level of Event Driven Consumer and that is by design, hence my question.
We're using Spring Boot for an application, with Camel for routing. We split most routes with an endpoint "URI" String, mainly for testability's sake:
rest("/foo").post().to("direct:foo");
from("direct:foo").process(exchange -> {
exchange.getIn().setBody(service.doStuff());
exchange.getIn().setHeader(Exchange.CONTENT_TYPE, CONTENT_TYPE_JSON);
});
However if we mis-type one of the "direct:foo" strings, we don't get an error until the route is invoked. I'd like to be able to get the error earlier, as part of the application's startup process.
Obviously using static finals instead of String literals will keep us from mis-typing an individual endpoint value, but it won't help with the situation where one endpoint doesn't go anywhere, or we're using one for a from without sending anything to it.
Is there a way I can ask Camel to verify all routes have working to/from endpoints, once Spring has finished scanning the classpath and building beans?