need to call two branches with in one git repository - java

I have a spring client application which is using a cloud server, I have a branch for each environment, for example, client STAG points to STAG branch in http://#giturl.So, what I'm trying to do is creating another branch called common which consists of common properties across the environment. I want to point STAG branch from client application to cloud server and as well as to common branch which retrieves all the common properties used across all the environments, Tried to use the composite type in a cloud server in application.yml by defining the same URL and different labels no luck on that any thoughts?
Tried using the composite type but didn't worked
spring:
profiles:
active: composite
cloud:
config:
server:
composite:
-
type:
git:
uri: https://#gitURI
searchPaths: '{application}/,common/'
-
type:
git:
uri: https://#gitURI
searchPaths: '{application}/'

Ok, so you might to look at this part of the documentation and play with those 3 properties at the client app, where label would be the branch names in a comma separated string. The searchPaths property at the server's side would be {application} since that is the subfolder.
You might want to consider having multiple config repositories since that will be easier to manage.
Hope that helps! :)

Related

Load multiple KEY/VALUE from Consul from different YML

Currently I have consul configured to read a YML and load different properties as follows in bootstrap.yml:
spring:
cloud:
consul:
host: ${CONSUL_HOST}
port: ${CONSUL_PORT}
config:
format: YAML
acl-token: ${CONSUL_TOKEN}
default-context: application
prefix: config/
name: application
data-key: data/properties
This works correctly.
Now I have included another Key/Value in consul at the same level as "properties", which is as follows:
config/application/data/properties
config/application/data/newproperties
I am trying to be able to load both data keys at the same time so that I can keep the different settings separate, but I am not managing to properly configure bootstrap.yml for this to happen.
I've tried setting the type as FILES, but haven't gotten it to work.
Have any of you faced this problem before?
Thanks!
After investigating and debugging the consul key/value behavior, it seems that it is not possible to read two different keys simultaneously.

How to integrate GraphiQL with Spring-Boot?

My target is to build a GraphQL server on Spring with (1) GraphiQL IDE (2) dynamic GraphQL schema at run-time. My GraphQL engine is GraphQL-Java.
In my first try, I use graphql-java-spring-boot-starter-webmvc and graphiql-spring-boot-starter.
Both the GraphQL server and the GraphiQL work well.
However, under the graphql-java-spring-boot-starter-webmvc framework, a #Bean of GraphQL class is needed. In this bean, the schema is loaded when the server starts so it could not been updated.
In my second try, I don't use graphql-java-spring-boot-starter-webmvc. Instead, I choose spring-boot-starter-web to start the web server and define my own RestController. This is easy to update the GraphQL instance. But I don't find a way to integrate with GraphiQL. I googled GraphiQL+Spring but all solutions are with graphql-java-spring-boot-starter.
Appreciate if anyone could provide me an idea on either approach.
It can be enabled in properties:
graphql.graphiql.enabled=true
It is accessible via the root url +/graphiql example http://localhost:8080/graphiql
You can find a good detailed example here : https://github.com/NoorKrichen/GraphQL-Spring-Boot-Example
Do you have a sample of your setup in git?
It sounds like some configuration problem. But naturally using graphql-java-spring-boot-starter-webmvc all your *.graphql schemas should be picked up in the configured schema resource path. check if you have the path set in your application.yml or if your schema is in the configured path if its already set or by default.
On your second point: "I googled GraphiQL+Spring but all solutions are with graphql-java-spring-boot-starter."
This makes sense for quick guides and demos as using Springboot the plumbing is somehow hidden away from you so that you can focus on the technology at hand being demo'd in this case GraphQl.
On GraphiQL:
Sounds like you are intending to have this embedded with your application, you may not want to do so in production. Depending on your use case there are many other alternatives that are standalone and gives you all the functionality of GraphiQL plus more e.g Altair Graphql Client and Insomnia to name a few.

How to initialize properties from code instead of from my application-dev.yml, application-prod.yml

My springboot application has a few yml files(each for various profiles - dev, prod) to load configurations from. I am moving the configurations to the DB.
Sample configurations are like,
admin:
id: user05
firstname: Brian
lastname: Leavy
purl: http://plixes.com/seai/ji
I have the values read from the DB and have it locally. I am not sure how to inject these values in my program onto these values, like key-value, as,
admin.id:user05
admin.firstname: Brian
admin.lastname: Leavy
admin.purl: http://plixes.com/seai/ji
so that they are available to the application as it would normally be.
I would need them to be initialized very early since some of the values are springboot configurations, like say,
server:
port: 5007
Any pointers would be really helpful.
EDIT1:
I just found out after hours of searching, that you could do something like this,
SpringApplication app = new SpringApplication(Lexon.class);
app.setDefaultProperties(Collections
.singletonMap("server.port", "5007"));
app.setDefaultProperties(Collections
.singletonMap("admin.id", "user05"));
This works, but does not look clean.
Is there a better way to do this?
There is Spring Boot Configuration library that can externalize the configuration to a database or a git repository.
With that, you add an data source and an SQL statement to retrieve the property values.
For example, on application.yml:
spring:
cloud:
config:
server:
jdbc:
sql: SELECT KEY, VALUE from MY_PROPERTIES where APPLICATION=? and PROFILE=? and LABEL=?
Check this site for more details: https://www.devglan.com/spring-cloud/jdbc-backend-spring-cloud-config

To bring up a spring-cloud-config-server component with multiple git url

How to map a URI to another URI in the application.yml of a spring-cloud-config server ?
I'm trying to deploy my spring-cloud-config-server application using Jenkins. I've defined the Git URL as <gitRepo>/{profile}-application.properties. Because I'm deploying the application without sending the profile, it is taking default as the profile and application is trying to reach <gitRepo>/default-application.properties which doesn't exist and therefore the health check on the application is failing as a part of the jenkins pipeline.
I now want to map URI : <gitRepo>/default-application.properties to URI : <gitRepo>/cit-application.properties.
Can this be done in the YML? I found many ways to only have multiple URIs based on the repositories, but that is not what I'm looking for.
spring:
cloud:
config:
server:
git:
uri: https://<gitrepo>/{profile}-configuration.git
pattern:
- '*/default-configuration'
uri: https://<gitrepo>/cit-configuration.git
we've disabled the health check by using
healthcheck:
enabled: false
That helped us resolve the issue.

Zipkin using Consul service name

For some reason Zipkin is using the Consul discovery name instead of the base spring.application.name property.
spring:
consul:
discovery:
prefer-ip-address: true
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
But I want it to use the non-randomized application name (so myservice instead of myservice-67gg8d368).
If I set the Zipkin property zipkin.service.name then Consul throws errors saying it cannot find the service.
I'm unsure why the two are even sharing properties and not just adhering to their own. I'd like the service to use it's base application name because otherwise Zipkin is hard to use, as it lists every new container as a completely new service, making it very difficult to see over time how code changes have changed timing.
UPDATE:
This is the error I get in my logs if I set the zipkin.service.name
[o.s.c.c.d.ConsulDiscoveryClient] : Unable to locate service in consul agent: my-service-91828f2f88f18c3fadf193bfa3ad6d1f

Categories

Resources