├── assets
└── diagram.png
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ ├── maven-wrapper.properties
│ └── MavenWrapperDownloader.java
├── name-client-service
├── src
│ └── main
│ │ ├── fabric8
│ │ ├── service.yml
│ │ ├── serviceAccount.yml
│ │ ├── configmap.yml
│ │ └── deployment.yml
│ │ ├── WEB-INF
│ │ └── beans.xml
│ │ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── jamesnetherton
│ │ │ ├── servlet
│ │ │ └── MetricsServlet.java
│ │ │ └── client
│ │ │ ├── producer
│ │ │ ├── KubernetesClientProducer.java
│ │ │ ├── JaxrsClientProducer.java
│ │ │ └── PropertiesComponentProducer.java
│ │ │ ├── ClientServiceRouteBuilder.java
│ │ │ ├── generator
│ │ │ └── NameGenerator.java
│ │ │ └── watcher
│ │ │ └── ConfigMapWatcher.java
│ │ └── resources
│ │ └── names.txt
└── pom.xml
├── name-suffix-service
├── src
│ └── main
│ │ ├── resources
│ │ ├── application.properties
│ │ ├── words.txt
│ │ └── lastnames.txt
│ │ ├── fabric8
│ │ └── service.yml
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── jamesnetherton
│ │ └── service
│ │ └── suffix
│ │ ├── SuffixServiceApplication.java
│ │ ├── SuffixServiceRouteBuilder.java
│ │ ├── processor
│ │ └── LastNameProcessor.java
│ │ └── OpenTracingConfig.java
└── pom.xml
├── etc
├── grafana
│ └── provisioning
│ │ ├── dashboards
│ │ ├── dashboard.yml
│ │ └── camel-microservice-demo.json
│ │ └── datasources
│ │ └── datasource.yml
└── prometheus
│ ├── server
│ ├── alert-rule-camel.yml
│ └── prometheus.yml
│ ├── alertmanager
│ └── config.yml
│ ├── prometheus-openshift.yml
│ └── agent
│ └── prometheus-config.yml
├── name-prefix-service
├── src
│ └── main
│ │ ├── resources
│ │ ├── application.properties
│ │ └── titles.txt
│ │ ├── fabric8
│ │ └── service.yml
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── jamesnetherton
│ │ └── service
│ │ └── prefix
│ │ ├── PrefixServiceApplication.java
│ │ ├── PrefixServiceRouteBuilder.java
│ │ ├── processor
│ │ └── TitleProcessor.java
│ │ └── OpenTracingConfig.java
└── pom.xml
├── .gitignore
├── pom.xml
├── docker-compose.yml
├── deployment-kubernetes.yml
├── README.md
├── mvnw.cmd
├── deployment-openshift.yml
└── mvnw
/assets/diagram.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jamesnetherton/camel-microservice-demo/HEAD/assets/diagram.png
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jamesnetherton/camel-microservice-demo/HEAD/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/name-client-service/src/main/fabric8/service.yml:
--------------------------------------------------------------------------------
1 | metadata:
2 | labels:
3 | hystrix.enabled: "true"
4 | spec:
5 | type: "NodePort"
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
--------------------------------------------------------------------------------
/name-client-service/src/main/fabric8/serviceAccount.yml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: "v1"
3 | kind: "ServiceAccount"
4 | metadata:
5 | name: "name-client-service"
--------------------------------------------------------------------------------
/name-client-service/src/main/fabric8/configmap.yml:
--------------------------------------------------------------------------------
1 | kind: ConfigMap
2 | apiVersion: v1
3 | metadata:
4 | name: client-service-config
5 | data:
6 | timer.period: 10000
--------------------------------------------------------------------------------
/name-suffix-service/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | camel.springboot.name=name-suffix-service
2 |
3 | server.port=8082
4 | server.address=0.0.0.0
5 | management.address=0.0.0.0
6 |
7 | camel.component.servlet.mapping.context-path=/api/*
8 |
--------------------------------------------------------------------------------
/etc/grafana/provisioning/dashboards/dashboard.yml:
--------------------------------------------------------------------------------
1 | apiVersion: 1
2 |
3 | providers:
4 | - name: 'Prometheus'
5 | orgId: 1
6 | folder: ''
7 | type: file
8 | disableDeletion: false
9 | editable: true
10 | options:
11 | path: /etc/grafana/provisioning/dashboards
12 |
--------------------------------------------------------------------------------
/etc/prometheus/server/alert-rule-camel.yml:
--------------------------------------------------------------------------------
1 | groups:
2 | - name: camel-microservice-demo
3 | rules:
4 | - alert: PrefixServiceInstanceDown
5 | expr: up{instance="name-prefix-service:9779"} == 0
6 | for: 1m
7 | annotations:
8 | summary: Prefix Service Down
9 |
--------------------------------------------------------------------------------
/name-prefix-service/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | camel.springboot.name=name-prefix-service
2 | suffix.service.host.name=name-suffix-service
3 |
4 | server.port=8081
5 | server.address=0.0.0.0
6 | management.address=0.0.0.0
7 |
8 | camel.component.servlet.mapping.context-path=/api/*
9 |
--------------------------------------------------------------------------------
/etc/prometheus/alertmanager/config.yml:
--------------------------------------------------------------------------------
1 | global:
2 | resolve_timeout: 5m
3 | route:
4 | group_by: ['job']
5 | group_wait: 30s
6 | group_interval: 1m
7 | receiver: 'webhook'
8 | receivers:
9 | - name: 'webhook'
10 | webhook_configs:
11 | - url: 'http://alert-webhook-logger:9876/'
12 |
--------------------------------------------------------------------------------
/name-suffix-service/src/main/fabric8/service.yml:
--------------------------------------------------------------------------------
1 | metadata:
2 | name: "name-suffix-service"
3 | spec:
4 | ports:
5 | - port: 80
6 | protocol: "TCP"
7 | targetPort: 8082
8 | name: http
9 | - port: 9779
10 | protocol: "TCP"
11 | targetPort: 9779
12 | name: prometheus
13 | type: "NodePort"
--------------------------------------------------------------------------------
/name-client-service/src/main/WEB-INF/beans.xml:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/name-prefix-service/src/main/fabric8/service.yml:
--------------------------------------------------------------------------------
1 | metadata:
2 | labels:
3 | name: "name-prefix-service"
4 | spec:
5 | ports:
6 | - port: 80
7 | protocol: "TCP"
8 | targetPort: 8081
9 | name: http
10 | - port: 9779
11 | protocol: "TCP"
12 | targetPort: 9779
13 | name: prometheus
14 | type: "NodePort"
--------------------------------------------------------------------------------
/name-client-service/src/main/java/com/github/jamesnetherton/servlet/MetricsServlet.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.servlet;
2 |
3 | import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
4 |
5 | import javax.servlet.annotation.WebServlet;
6 |
7 | @WebServlet(name = "HystrixMetricsStreamServlet", urlPatterns = {"/hystrix.stream"})
8 | public class MetricsServlet extends HystrixMetricsStreamServlet {
9 | }
--------------------------------------------------------------------------------
/name-suffix-service/src/main/resources/words.txt:
--------------------------------------------------------------------------------
1 | Burp
2 | Hall
3 | Ice
4 | Nut
5 | Duck
6 | Stove
7 | Muscle
8 | Flame
9 | Egg
10 | Crook
11 | Drain
12 | Sneeze
13 | Hose
14 | Glove
15 | Wood
16 | Bone
17 | Tooth
18 | Hall
19 | Ice
20 | Nut
21 | Duck
22 | Toothbrush
23 | Stove
24 | Muscle
25 | Flame
26 | Honey
27 | Bird
28 | Beer
29 | Burger
30 | Stranger
31 | Cheek
32 | Hat
33 | River
34 | Ladder
35 | Driver
36 | Ear
37 | Dirt
38 | Steak
39 | Farmer
40 | Cookie
--------------------------------------------------------------------------------
/name-suffix-service/src/main/java/com/github/jamesnetherton/service/suffix/SuffixServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.service.suffix;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SuffixServiceApplication {
8 |
9 | public static void main(String args[]) {
10 | SpringApplication.run(SuffixServiceApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/name-client-service/src/main/resources/names.txt:
--------------------------------------------------------------------------------
1 | Crissy
2 | Lynnette
3 | Concepcion
4 | Gearldine
5 | Tari
6 | Sherie
7 | Loria
8 | Magdalene
9 | Crystal
10 | Kacey
11 | Golda
12 | Thea
13 | Shavonda
14 | Renda
15 | Rebecka
16 | Maddie
17 | Ligia
18 | Dominque
19 | Joycelyn
20 | Bambi
21 | Bryan
22 | Kirk
23 | Desmond
24 | Willard
25 | Rene
26 | Domingo
27 | Brad
28 | Denny
29 | Teddy
30 | Junior
31 | Josh
32 | Nathaniel
33 | Reyes
34 | Eusebio
35 | Guillermo
36 | Emmanuel
37 | Wilburn
38 | Garfield
39 | Brenton
40 | Buford
--------------------------------------------------------------------------------
/name-suffix-service/src/main/resources/lastnames.txt:
--------------------------------------------------------------------------------
1 | Seibold
2 | Morganella
3 | Boix
4 | Farneti
5 | Sabatello
6 | Conlon
7 | Harbron
8 | Forsberg
9 | Nakkula
10 | Berson
11 | Vorhaus
12 | Kotter
13 | Milenkovic
14 | Castagna
15 | Mann
16 | Rundlett
17 | Higonnet
18 | Strominger
19 | Jeffery
20 | Caligor
21 | Sailer
22 | Kubacki
23 | Adam
24 | Charrette
25 | Towne
26 | Mccall
27 | Meller
28 | Rankine
29 | Mahood
30 | Tabler
31 | Przekop
32 | Godoy
33 | Aisner
34 | Hartman
35 | Katsos
36 | Solc
37 | Ristich
38 | Josselson
39 | Alcantar
40 | Wiltse
--------------------------------------------------------------------------------
/name-client-service/src/main/java/com/github/jamesnetherton/client/producer/KubernetesClientProducer.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.client.producer;
2 |
3 | import io.fabric8.kubernetes.client.DefaultKubernetesClient;
4 | import io.fabric8.kubernetes.client.KubernetesClient;
5 |
6 | import javax.enterprise.context.ApplicationScoped;
7 | import javax.enterprise.inject.Produces;
8 |
9 | @ApplicationScoped
10 | public class KubernetesClientProducer {
11 |
12 | @Produces
13 | public KubernetesClient kubernetesClient() {
14 | return new DefaultKubernetesClient();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/name-prefix-service/src/main/java/com/github/jamesnetherton/service/prefix/PrefixServiceApplication.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.service.prefix;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.boot.web.servlet.ServletComponentScan;
6 |
7 | @SpringBootApplication
8 | @ServletComponentScan(basePackages = "com.github.jamesnetherton.service.prefix.servlet")
9 | public class PrefixServiceApplication {
10 |
11 | public static void main(String args[]) {
12 | SpringApplication.run(PrefixServiceApplication.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/etc/grafana/provisioning/datasources/datasource.yml:
--------------------------------------------------------------------------------
1 | apiVersion: 1
2 |
3 | deleteDatasources:
4 | - name: Prometheus
5 | orgId: 1
6 |
7 | datasources:
8 | - name: Prometheus
9 | type: prometheus
10 | access: proxy
11 | orgId: 1
12 | url: http://prometheus:9090
13 | password:
14 | user:
15 | database:
16 | basicAuth: false
17 | basicAuthUser:
18 | basicAuthPassword:
19 | withCredentials:
20 | isDefault: true
21 | jsonData:
22 | graphiteVersion: "1.1"
23 | tlsAuth: false
24 | tlsAuthWithCACert: false
25 | secureJsonData:
26 | tlsCACert: "..."
27 | tlsClientCert: "..."
28 | tlsClientKey: "..."
29 | version: 1
30 | editable: true
31 |
--------------------------------------------------------------------------------
/name-client-service/src/main/java/com/github/jamesnetherton/client/producer/JaxrsClientProducer.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.client.producer;
2 |
3 | import io.opentracing.contrib.jaxrs2.client.ClientTracingFeature;
4 |
5 | import javax.enterprise.context.ApplicationScoped;
6 | import javax.enterprise.inject.Produces;
7 | import javax.ws.rs.client.Client;
8 | import javax.ws.rs.client.ClientBuilder;
9 |
10 | @ApplicationScoped
11 | public class JaxrsClientProducer {
12 |
13 | @Produces
14 | public Client resteasyClient() {
15 | return ClientBuilder.newBuilder()
16 | .register(ClientTracingFeature.class)
17 | .build();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.java.hsp
2 | *.sonarj
3 | *.sw*
4 | .DS_Store
5 | .settings
6 | .springBeans
7 | bin
8 | build.sh
9 | integration-repo
10 | ivy-cache
11 | jxl.log
12 | jmx.log
13 | derby.log
14 | spring-test/test-output/
15 | .gradle
16 | argfile*
17 | activemq-data/
18 |
19 | classes/
20 | /build
21 | buildSrc/build
22 | /spring-*/build
23 | /src/asciidoc/build
24 | target/
25 |
26 | # Eclipse artifacts, including WTP generated manifests
27 | .classpath
28 | .project
29 | spring-*/src/main/java/META-INF/MANIFEST.MF
30 |
31 | # IDEA artifacts and output dirs
32 | *.iml
33 | *.ipr
34 | *.iws
35 | .idea
36 | out
37 | test-output
38 | atlassian-ide-plugin.xml
39 | .gradletasknamecache
40 |
41 | etc/prometheus/alertmanager/data
--------------------------------------------------------------------------------
/name-suffix-service/src/main/java/com/github/jamesnetherton/service/suffix/SuffixServiceRouteBuilder.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.service.suffix;
2 |
3 | import com.github.jamesnetherton.service.suffix.processor.LastNameProcessor;
4 | import org.apache.camel.builder.RouteBuilder;
5 | import org.springframework.stereotype.Component;
6 |
7 | @Component
8 | public class SuffixServiceRouteBuilder extends RouteBuilder {
9 |
10 | @Override
11 | public void configure() throws Exception {
12 | restConfiguration()
13 | .component("servlet")
14 | .contextPath("/api");
15 |
16 | rest()
17 | .post("/name/suffix")
18 | .route().id("name-suffix-service")
19 | .process(new LastNameProcessor());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/etc/prometheus/server/prometheus.yml:
--------------------------------------------------------------------------------
1 | global:
2 | scrape_interval: 15s
3 | evaluation_interval: 15s
4 |
5 | rule_files:
6 | - 'alert-rule-camel.yml'
7 |
8 | alerting:
9 | alertmanagers:
10 | - scheme: http
11 | static_configs:
12 | - targets:
13 | - 'alertmanager:9093'
14 |
15 | scrape_configs:
16 |
17 | - job_name: 'prometheus'
18 |
19 | static_configs:
20 | - targets:
21 | - 'localhost:9090'
22 |
23 | - job_name: 'cadvisor'
24 |
25 | static_configs:
26 | - targets:
27 | - 'cadvisor:8080'
28 |
29 | - job_name: 'node-exporter'
30 |
31 | static_configs:
32 | - targets:
33 | - 'node-exporter:9100'
34 |
35 | - job_name: 'camel-microservice-demo'
36 |
37 | static_configs:
38 | - targets:
39 | - 'name-client-service:9779'
40 | - 'name-prefix-service:9779'
41 | - 'name-suffix-service:9779'
--------------------------------------------------------------------------------
/name-prefix-service/src/main/java/com/github/jamesnetherton/service/prefix/PrefixServiceRouteBuilder.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.service.prefix;
2 |
3 | import com.github.jamesnetherton.service.prefix.processor.TitleProcessor;
4 | import org.apache.camel.builder.RouteBuilder;
5 | import org.springframework.stereotype.Component;
6 |
7 | @Component
8 | public class PrefixServiceRouteBuilder extends RouteBuilder {
9 |
10 | @Override
11 | public void configure() throws Exception {
12 | restConfiguration()
13 | .contextPath("/api")
14 | .component("servlet");
15 |
16 | rest()
17 | .post("/name/prefix")
18 | .route().routeId("name-prefix-service")
19 | .removeHeaders("CamelHttp*")
20 | .process(new TitleProcessor())
21 | .to("http://{{suffix.service.host.name}}/api/name/suffix")
22 | .end();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/name-client-service/src/main/java/com/github/jamesnetherton/client/producer/PropertiesComponentProducer.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.client.producer;
2 |
3 | import org.apache.camel.component.properties.PropertiesComponent;
4 |
5 | import javax.enterprise.context.ApplicationScoped;
6 | import javax.enterprise.inject.Produces;
7 | import javax.inject.Named;
8 | import java.util.Map;
9 | import java.util.Properties;
10 |
11 | @ApplicationScoped
12 | public class PropertiesComponentProducer {
13 |
14 | @Produces
15 | @Named("properties")
16 | public PropertiesComponent propertiesComponent() {
17 | PropertiesComponent component = new PropertiesComponent();
18 | Properties properties = new Properties();
19 |
20 | for (Map.Entry env : System.getenv().entrySet()) {
21 | properties.put(env.getKey(), env.getValue());
22 | }
23 |
24 | component.setInitialProperties(properties);
25 | return component;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/name-client-service/src/main/java/com/github/jamesnetherton/client/ClientServiceRouteBuilder.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.client;
2 |
3 | import com.github.jamesnetherton.lolcat4j.Lol;
4 | import org.apache.camel.builder.RouteBuilder;
5 | import org.apache.camel.cdi.ContextName;
6 |
7 | import javax.enterprise.context.ApplicationScoped;
8 |
9 | @ApplicationScoped
10 | @ContextName("client-camel-context")
11 | public class ClientServiceRouteBuilder extends RouteBuilder {
12 |
13 | @Override
14 | public void configure() throws Exception {
15 | from("timer:generateName?period=10000").id("name-client-service")
16 | .hystrix()
17 | .bean("nameGenerator")
18 | .onFallback()
19 | .setBody(constant("Sorry. Name could not be generated."))
20 | .end()
21 | .process(exchange -> {
22 | String name = exchange.getIn().getBody(String.class);
23 | Lol lol = Lol.builder()
24 | .text(name)
25 | .build();
26 | lol.cat();
27 | });
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/name-client-service/src/main/fabric8/deployment.yml:
--------------------------------------------------------------------------------
1 | metadata:
2 | labels:
3 | hystrix.enabled: "true"
4 | spec:
5 | selector:
6 | matchLabels:
7 | hystrix.enabled: "true"
8 | template:
9 | metadata:
10 | labels:
11 | hystrix.enabled: "true"
12 | spec:
13 | serviceAccountName: "camel-microservice-demo"
14 | containers:
15 | - env:
16 | - name: "AB_OFF"
17 | value: "true"
18 | - name: "JAVA_OPTIONS"
19 | value: "-Djava.net.preferIPv4Stack=true"
20 | - name: "JAEGER_SERVICE_NAME"
21 | value: "camel-microservice-demo"
22 | - name: "JAEGER_REPORTER_LOG_SPANS"
23 | value: "false"
24 | - name: "JAEGER_SAMPLER_TYPE"
25 | value: "const"
26 | - name: "JAEGER_SAMPLER_PARAM"
27 | value: "1"
28 | - name: "JAEGER_AGENT_HOST"
29 | value: "opentracing"
30 | - name: "JAEGER_AGENT_PORT"
31 | value: "6831"
32 | readinessProbe:
33 | httpGet:
34 | path: /health
35 | port: 8080
36 | scheme: HTTP
37 | livenessProbe:
38 | httpGet:
39 | path: /health
40 | port: 8080
41 | scheme: HTTP
42 | initialDelaySeconds: 180
--------------------------------------------------------------------------------
/name-prefix-service/src/main/java/com/github/jamesnetherton/service/prefix/processor/TitleProcessor.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.service.prefix.processor;
2 |
3 | import org.apache.camel.Exchange;
4 | import org.apache.camel.Processor;
5 |
6 | import java.io.BufferedReader;
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.InputStreamReader;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import java.util.Random;
13 |
14 | public class TitleProcessor implements Processor {
15 | private List titles = new ArrayList<>();
16 | private Random random = new Random();
17 |
18 | public TitleProcessor() {
19 | InputStream resource = TitleProcessor.class.getClassLoader().getResourceAsStream("titles.txt");
20 | if (resource == null) {
21 | throw new IllegalStateException("Unable to load titles");
22 | }
23 |
24 | try(BufferedReader reader = new BufferedReader(new InputStreamReader(resource))) {
25 | String line;
26 | while((line = reader.readLine()) != null) {
27 | titles.add(line);
28 | }
29 | } catch (IOException e) {
30 | throw new IllegalStateException("Error reading titles", e);
31 | }
32 | }
33 |
34 | @Override
35 | public void process(Exchange exchange) throws Exception {
36 | String name = exchange.getIn().getHeader("name", String.class);
37 | String randomTitle = titles.get(random.nextInt(titles.size() - 1));
38 |
39 | exchange.getOut().setBody(randomTitle + " " + name);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/name-suffix-service/src/main/java/com/github/jamesnetherton/service/suffix/processor/LastNameProcessor.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.service.suffix.processor;
2 |
3 | import org.apache.camel.Exchange;
4 | import org.apache.camel.Processor;
5 |
6 | import java.io.BufferedReader;
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.InputStreamReader;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import java.util.Random;
13 |
14 | public class LastNameProcessor implements Processor {
15 | private List lastNames = new ArrayList<>();
16 | private List words = new ArrayList<>();
17 | private Random random = new Random();
18 |
19 | public LastNameProcessor() {
20 | buildList(lastNames, "lastnames.txt");
21 | buildList(words, "words.txt");
22 | }
23 |
24 | @Override
25 | public void process(Exchange exchange) throws Exception {
26 | String name = exchange.getIn().getBody(String.class);
27 | String randomLastName = lastNames.get(random.nextInt(lastNames.size() - 1));
28 | String randomWord = words.get(random.nextInt(words.size() - 1));
29 |
30 | exchange.getIn().setBody(name + " " + randomLastName + "-" + randomWord);
31 | }
32 |
33 | private void buildList(List list, String resource) {
34 | InputStream inputStream = LastNameProcessor.class.getClassLoader().getResourceAsStream(resource);
35 |
36 | if (inputStream == null) {
37 | throw new IllegalStateException("InputStream is null");
38 | }
39 |
40 | try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
41 | String line;
42 | while((line = reader.readLine()) != null) {
43 | list.add(line);
44 | }
45 | } catch (IOException e) {
46 | throw new IllegalStateException("Error reading from InputStream", e);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/name-suffix-service/src/main/java/com/github/jamesnetherton/service/suffix/OpenTracingConfig.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.service.suffix;
2 |
3 | import io.jaegertracing.samplers.ConstSampler;
4 | import org.apache.camel.CamelContext;
5 | import org.apache.camel.opentracing.OpenTracingTracer;
6 | import org.springframework.beans.factory.annotation.Value;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 |
10 | @Configuration
11 | public class OpenTracingConfig {
12 |
13 | @Bean
14 | public io.jaegertracing.Configuration jaegerConfiguration(@Value("#{environment['OPENTRACING_SERVICE_HOST'] ?: 'localhost'}") String host,
15 | @Value("#{environment['OPENTRACING_SERVICE_PORT_OPENTRACING_DATA'] ?: 6831}") int port) {
16 | io.jaegertracing.Configuration.SamplerConfiguration samplerConfig = new io.jaegertracing.Configuration.SamplerConfiguration()
17 | .withType(ConstSampler.TYPE)
18 | .withParam(1);
19 | io.jaegertracing.Configuration.SenderConfiguration senderConfig = new io.jaegertracing.Configuration.SenderConfiguration()
20 | .withAgentHost(host)
21 | .withAgentPort(port);
22 | io.jaegertracing.Configuration.ReporterConfiguration reporterConfig = new io.jaegertracing.Configuration.ReporterConfiguration()
23 | .withLogSpans(true)
24 | .withFlushInterval(1000)
25 | .withMaxQueueSize(10000)
26 | .withSender(senderConfig);
27 | return new io.jaegertracing.Configuration("name-suffix-service")
28 | .withSampler(samplerConfig)
29 | .withReporter(reporterConfig);
30 | }
31 |
32 | @Bean
33 | public OpenTracingTracer openTracingTracer(io.jaegertracing.Configuration jaegerConfiguration, CamelContext camelContext) {
34 | OpenTracingTracer tracer = new OpenTracingTracer();
35 | tracer.setTracer(jaegerConfiguration.getTracer());
36 | tracer.init(camelContext);
37 | return tracer;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/name-prefix-service/src/main/resources/titles.txt:
--------------------------------------------------------------------------------
1 | Mr
2 | Mrs
3 | Ms
4 | Miss
5 | Dr
6 | Herr
7 | Monsieur
8 | Hr
9 | Frau
10 | Admiraal
11 | Admiral
12 | Air Cdre
13 | Air Commodore
14 | Air Marshal
15 | Air Vice Marshal
16 | Alderman
17 | Alhaji
18 | Ambassador
19 | Baron
20 | Barones
21 | Brig
22 | Brig Gen
23 | Brig General
24 | Brigadier
25 | Brigadier General
26 | Brother
27 | Canon
28 | Capt
29 | Captain
30 | Cardinal
31 | Cdr
32 | Chief
33 | Cik
34 | Cmdr
35 | Col
36 | Col Dr
37 | Colonel
38 | Commandant
39 | Commander
40 | Commissioner
41 | Commodore
42 | Comte
43 | Comtessa
44 | Congressman
45 | Conseiller
46 | Consul
47 | Conte
48 | Contessa
49 | Corporal
50 | Councillor
51 | Count
52 | Countess
53 | Crown Prince
54 | Crown Princess
55 | Dame
56 | Datin
57 | Dato
58 | Datuk
59 | Datuk Seri
60 | Deacon
61 | Deaconess
62 | Dean
63 | Dhr
64 | Dipl Ing
65 | Doctor
66 | Dott
67 | Dott sa
68 | Dr
69 | Dr Ing
70 | Dra
71 | Drs
72 | Embajador
73 | Embajadora
74 | En
75 | Encik
76 | Eng
77 | Eur Ing
78 | Exma Sra
79 | Exmo Sr
80 | F O
81 | Father
82 | First Lieutient
83 | First Officer
84 | Flt Lieut
85 | Flying Officer
86 | Fr
87 | Frau
88 | Fraulein
89 | Fru
90 | Gen
91 | Generaal
92 | General
93 | Governor
94 | Graaf
95 | Gravin
96 | Group Captain
97 | Grp Capt
98 | H E Dr
99 | H H
100 | H M
101 | H R H
102 | Hajah
103 | Haji
104 | Hajim
105 | Her Highness
106 | Her Majesty
107 | Herr
108 | High Chief
109 | His Highness
110 | His Holiness
111 | His Majesty
112 | Hon
113 | Hr
114 | Hra
115 | Ing
116 | Ir
117 | Jonkheer
118 | Judge
119 | Justice
120 | Khun Ying
121 | Kolonel
122 | Lady
123 | Lcda
124 | Lic
125 | Lieut
126 | Lieut Cdr
127 | Lieut Col
128 | Lieut Gen
129 | Lord
130 | M
131 | M L
132 | M R
133 | Madame
134 | Mademoiselle
135 | Maj Gen
136 | Major
137 | Master
138 | Mevrouw
139 | Miss
140 | Mlle
141 | Mme
142 | Monsieur
143 | Monsignor
144 | Mr
145 | Mrs
146 | Ms
147 | Mstr
148 | Nti
149 | Pastor
150 | President
151 | Prince
152 | Princess
153 | Princesse
154 | Prinses
155 | Prof
156 | Prof Dr
157 | Prof Sir
158 | Professor
159 | Puan
160 | Puan Sri
161 | Rabbi
162 | Rear Admiral
163 | Rev
164 | Rev Canon
165 | Rev Dr
166 | Rev Mother
167 | Reverend
168 | Rva
169 | Senator
170 | Sergeant
171 | Sheikh
172 | Sheikha
173 | Sig
174 | Sig na
175 | Sig ra
176 | Sir
177 | Sister
178 | Sqn Ldr
179 | Sr
180 | Sr D
181 | Sra
182 | Srta
183 | Sultan
184 | Tan Sri
185 | Tan Sri Dato
186 | Tengku
187 | Teuku
188 | Than Puying
189 | The Hon Dr
190 | The Hon Justice
191 | The Hon Miss
192 | The Hon Mr
193 | The Hon Mrs
194 | The Hon Ms
195 | The Hon Sir
196 | The Very Rev
197 | Toh Puan
198 | Tun
199 | Vice Admiral
200 | Viscount
201 | Viscountess
202 | Wg Cdr
--------------------------------------------------------------------------------
/name-client-service/src/main/java/com/github/jamesnetherton/client/generator/NameGenerator.java:
--------------------------------------------------------------------------------
1 | package com.github.jamesnetherton.client.generator;
2 |
3 | import org.apache.camel.PropertyInject;
4 |
5 | import javax.enterprise.context.ApplicationScoped;
6 | import javax.inject.Inject;
7 | import javax.inject.Named;
8 | import javax.ws.rs.client.Client;
9 | import javax.ws.rs.client.Entity;
10 | import javax.ws.rs.core.Form;
11 | import javax.ws.rs.core.Response;
12 | import java.io.BufferedReader;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.io.InputStreamReader;
16 | import java.util.ArrayList;
17 | import java.util.List;
18 | import java.util.Random;
19 |
20 | import static javax.ws.rs.core.Response.Status.OK;
21 |
22 | @ApplicationScoped
23 | @Named("nameGenerator")
24 | public class NameGenerator {
25 | private List names = new ArrayList<>();
26 | private Random random = new Random();
27 |
28 | @Inject
29 | private Client client;
30 |
31 | @PropertyInject(value = "NAME_PREFIX_SERVICE_SERVICE_HOST", defaultValue = "localhost:8081")
32 | private String prefixServiceHost;
33 |
34 | public NameGenerator() {
35 | InputStream resource = NameGenerator.class.getClassLoader().getResourceAsStream("/names.txt");
36 | if (resource == null) {
37 | throw new IllegalStateException("Unable to load names");
38 | }
39 |
40 | try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource))) {
41 | String line;
42 | while ((line = reader.readLine()) != null) {
43 | names.add(line);
44 | }
45 | } catch (IOException e) {
46 | throw new IllegalStateException("Error reading names", e);
47 | }
48 | }
49 |
50 | public String generateName() {
51 | String result = "";
52 | String randomName = names.get(random.nextInt(names.size() - 1));
53 |
54 | Form form = new Form();
55 | form.param("name", randomName);
56 |
57 | Entity