In order to demonstrate MicroProfile Config, the 'articles' service uses a configuration to define whether or not to create ten articles the first time it is invoked.
In the yaml file an environment variable pointing to a ConfigMap is defined.
kind: Deployment
apiVersion: apps/v1beta1
metadata:
name: articles
spec:
replicas: 1
template:
metadata:
labels:
app: articles
version: v1
spec:
containers:
- name: articles
image: articles:1
ports:
- containerPort: 8080
env:
- name: samplescreation
valueFrom:
configMapKeyRef:
name: articles-config
key: samplescreation
restartPolicy: Always
---
kind: ConfigMap
apiVersion: v1
metadata:
name: articles-config
data:
samplescreation: "true"
In the Java code the configuration can be accessed via @Inject and @ConfigProperty.
public class CoreService {
@Inject
@ConfigProperty(name = "samplescreation", defaultValue = "false")
private boolean samplescreation;
@PostConstruct
private void addArticles() {
if (samplescreation)
addSampleArticles();
}
Invoke the following commands to set up the demo. Skip the commands you've already executed.
$ cd $PROJECT_HOME
$ scripts/check-prerequisites.sh
$ scripts/delete-all.sh
$ scripts/deploy-articles-java-jee.sh
$ scripts/show-urls.sh
Invoke the curl command which is displayed as output of 'scripts/show-urls.sh' to get ten articles.
Check out the article Configuring Microservices with MicroProfile and Kubernetes for more details.