CAMEL-11714 - Add a Kubernetes Camel-gRPC spring-boot example
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d8602f26 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d8602f26 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d8602f26 Branch: refs/heads/master Commit: d8602f26dbbb8a5b5f11e07afd5f4d0242b87015 Parents: 2c5c8b6 Author: Andrea Cosentino <anco...@gmail.com> Authored: Wed Aug 30 09:44:08 2017 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Wed Aug 30 10:16:28 2017 +0200 ---------------------------------------------------------------------- .../camel-example-grpc-kubernetes/README.adoc | 99 +++++++++++++++----- .../hello-camel-grpc-client-kubernetes/pom.xml | 78 +++++++-------- .../example/springboot/grpc/CamelGrpcRoute.java | 2 +- .../hello-camel-grpc-server-kubernetes/pom.xml | 84 ++++++++++------- examples/pom.xml | 1 + 5 files changed, 163 insertions(+), 101 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/d8602f26/examples/camel-example-grpc-kubernetes/README.adoc ---------------------------------------------------------------------- diff --git a/examples/camel-example-grpc-kubernetes/README.adoc b/examples/camel-example-grpc-kubernetes/README.adoc index 637d5b4..be041fa 100644 --- a/examples/camel-example-grpc-kubernetes/README.adoc +++ b/examples/camel-example-grpc-kubernetes/README.adoc @@ -1,8 +1,8 @@ -# Spring Boot Example with gRPC +# Spring Boot Example with gRPC on Kubernetes ### Introduction -This example demonstrates how you can use Camel-gRPC Starter component. The example is composed of a standalone gRPC server and a Camel Spring-boot gRPC route acting as client. +This example demonstrates how you can use Camel-gRPC Starter component. The example is composed of a standalone gRPC server and a Camel Spring-boot gRPC route acting as client. We will run this example on Minikube (0.21.0) ### Server @@ -12,14 +12,28 @@ You can build the server under the directory hello-camel-grpc-server with: and then run the server with - $ mvn exec:java + $ mvn -Pkubernetes-install fabric8:deploy + +then check your pod status with + + $ kubectl get pods + +[source,bash] +---- +NAME READY STATUS RESTARTS AGE +camel-example-hello-grpc-server-kubernetes-2604940788-g47hr 1/1 Running 0 13s +---- + +and get the logs + + $ kubectl logs camel-example-hello-grpc-server-kubernetes-2604940788-g47hr You should see the following output: [source,bash] ---- -Aug 08, 2017 8:00:00 AM org.apache.camel.examples.grpc.HelloCamelServer start -INFO: Server started. I'm listening on 50051 +Aug 30, 2017 7:31:11 AM org.apache.camel.examples.grpc.HelloCamelServer start +INFO: Server started. I'm listening on 8080 ---- ### Run the client @@ -28,32 +42,67 @@ You can build the client example under the directory hello-camel-grpc-client wit $ mvn clean install -and then run the example with +and then run the server with + + $ mvn -Pkubernetes-install fabric8:deploy + +then check your pod status with + + $ kubectl get pods + +[source,bash] +---- +NAME READY STATUS RESTARTS AGE +camel-example-hello-grpc-client-kubernetes-1594657646-ptrkn 1/1 Running 0 15s +camel-example-hello-grpc-server-kubernetes-2604940788-g47hr 1/1 Running 0 7m + +---- + +and get the logs - $ mvn spring-boot:run + $ kubectl logs camel-example-hello-grpc-client-kubernetes-1594657646-ptrkn And you should see this output in the console. [source,bash] ---- -2017-08-08 08:01:14.530 INFO 7096 --- [ main] o.a.c.e.springboot.grpc.Application : Starting Application on ghost with PID 7096 (/home/oscerd/workspace/apache-camel/camel/examples/camel-example-spring-boot-grpc/hello-camel-grpc-client/target/classes started by oscerd in /home/oscerd/workspace/apache-camel/camel/examples/camel-example-spring-boot-grpc/hello-camel-grpc-client) -2017-08-08 08:01:14.532 INFO 7096 --- [ main] o.a.c.e.springboot.grpc.Application : No active profile set, falling back to default profiles: default -2017-08-08 08:01:14.563 INFO 7096 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@540ff973: startup date [Tue Aug 08 08:01:14 CEST 2017]; root of context hierarchy -2017-08-08 08:01:15.177 INFO 7096 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$78492c0f] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) -2017-08-08 08:01:15.447 INFO 7096 --- [ main] o.a.c.i.converter.DefaultTypeConverter : Type converters loaded (core: 192, classpath: 1) -2017-08-08 08:01:15.844 INFO 7096 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup -2017-08-08 08:01:15.894 INFO 7096 --- [ main] o.a.camel.spring.boot.RoutesCollector : Loading additional Camel XML routes from: classpath:camel/*.xml -2017-08-08 08:01:15.894 INFO 7096 --- [ main] o.a.camel.spring.boot.RoutesCollector : Loading additional Camel XML rests from: classpath:camel-rest/*.xml -2017-08-08 08:01:15.895 INFO 7096 --- [ main] o.a.camel.spring.boot.RoutesCollector : Starting CamelMainRunController to ensure the main thread keeps running -2017-08-08 08:01:15.898 INFO 7096 --- [inRunController] o.a.camel.spring.SpringCamelContext : Apache Camel 2.20.0-SNAPSHOT (CamelContext: gRPC) is starting -2017-08-08 08:01:15.899 INFO 7096 --- [inRunController] o.a.c.m.ManagedManagementStrategy : JMX is enabled -2017-08-08 08:01:15.904 INFO 7096 --- [ main] o.a.c.e.springboot.grpc.Application : Started Application in 1.897 seconds (JVM running for 7.75) -2017-08-08 08:01:16.074 INFO 7096 --- [inRunController] o.a.camel.spring.SpringCamelContext : StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html -2017-08-08 08:01:16.118 INFO 7096 --- [inRunController] o.a.camel.component.grpc.GrpcProducer : Creating channel to the remote gRPC server localhost:50051 -2017-08-08 08:01:16.214 INFO 7096 --- [inRunController] o.a.camel.spring.SpringCamelContext : Route: route1 started and consuming from: timer://foo?period=10000&repeatCount=1 -2017-08-08 08:01:16.216 INFO 7096 --- [inRunController] o.a.camel.spring.SpringCamelContext : Total 1 routes, of which 1 are started. -2017-08-08 08:01:16.216 INFO 7096 --- [inRunController] o.a.camel.spring.SpringCamelContext : Apache Camel 2.20.0-SNAPSHOT (CamelContext: gRPC) started in 0.319 seconds -2017-08-08 08:01:17.534 INFO 7096 --- [2 - timer://foo] route1 : Received message: "Hello Camel" +2017-08-30 07:38:50.753:INFO:ifasjipjsoejs.Server:jetty-8.y.z-SNAPSHOT +2017-08-30 07:38:50.787:INFO:ifasjipjsoejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:9779 + + . ____ _ __ _ _ + /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ +( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ + \\/ ___)| |_)| | | | | || (_| | ) ) ) ) + ' |____| .__|_| |_|_| |_\__, | / / / / + =========|_|==============|___/=/_/_/_/ + :: Spring Boot :: (v1.5.6.RELEASE) + +2017-08-30 07:38:51.742 INFO 1 --- [ main] o.a.c.e.springboot.grpc.Application : Starting Application v2.20.0-SNAPSHOT on camel-example-hello-grpc-client-kubernetes-1594657646-ptrkn with PID 1 (/deployments/camel-example-hello-grpc-client-kubernetes-2.20.0-SNAPSHOT.jar started by root in /deployments) +2017-08-30 07:38:51.744 INFO 1 --- [ main] o.a.c.e.springboot.grpc.Application : No active profile set, falling back to default profiles: default +2017-08-30 07:38:51.899 INFO 1 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5faeada1: startup date [Wed Aug 30 07:38:51 GMT 2017]; root of context hierarchy +2017-08-30 07:38:53.236 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.apache.camel.spring.boot.CamelAutoConfiguration' of type [org.apache.camel.spring.boot.CamelAutoConfiguration$$EnhancerBySpringCGLIB$$bd99dea4] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) +2017-08-30 07:38:54.109 INFO 1 --- [ main] o.a.c.i.converter.DefaultTypeConverter : Type converters loaded (core: 192, classpath: 1) +2017-08-30 07:38:54.906 INFO 1 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup +2017-08-30 07:38:54.976 INFO 1 --- [ main] o.a.camel.spring.boot.RoutesCollector : Loading additional Camel XML routes from: classpath:camel/*.xml +2017-08-30 07:38:54.977 INFO 1 --- [ main] o.a.camel.spring.boot.RoutesCollector : Loading additional Camel XML rests from: classpath:camel-rest/*.xml +2017-08-30 07:38:54.977 INFO 1 --- [ main] o.a.camel.spring.boot.RoutesCollector : Starting CamelMainRunController to ensure the main thread keeps running +2017-08-30 07:38:54.980 INFO 1 --- [inRunController] o.a.camel.spring.SpringCamelContext : Apache Camel 2.20.0-SNAPSHOT (CamelContext: gRPC) is starting +2017-08-30 07:38:54.983 INFO 1 --- [inRunController] o.a.c.m.ManagedManagementStrategy : JMX is enabled +2017-08-30 07:38:55.005 INFO 1 --- [ main] o.a.c.e.springboot.grpc.Application : Started Application in 3.745 seconds (JVM running for 4.657) +2017-08-30 07:38:55.308 INFO 1 --- [inRunController] o.a.camel.spring.SpringCamelContext : StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html +2017-08-30 07:38:55.387 INFO 1 --- [inRunController] o.a.camel.component.grpc.GrpcProducer : Creating channel to the remote gRPC server grpc-server:80 +2017-08-30 07:38:55.544 INFO 1 --- [inRunController] o.a.camel.spring.SpringCamelContext : Route: route1 started and consuming from: timer://foo?period=10000&repeatCount=5 +2017-08-30 07:38:55.545 INFO 1 --- [inRunController] o.a.camel.spring.SpringCamelContext : Total 1 routes, of which 1 are started +2017-08-30 07:38:55.546 INFO 1 --- [inRunController] o.a.camel.spring.SpringCamelContext : Apache Camel 2.20.0-SNAPSHOT (CamelContext: gRPC) started in 0.565 seconds +2017-08-30 07:38:57.443 INFO 1 --- [2 - timer://foo] route1 : Received message: "Hello Camel" + +2017-08-30 07:39:06.556 INFO 1 --- [2 - timer://foo] route1 : Received message: "Hello Camel" + +2017-08-30 07:39:16.551 INFO 1 --- [2 - timer://foo] route1 : Received message: "Hello Camel" + +2017-08-30 07:39:26.551 INFO 1 --- [2 - timer://foo] route1 : Received message: "Hello Camel" + +2017-08-30 07:39:36.551 INFO 1 --- [2 - timer://foo] route1 : Received message: "Hello Camel" ---- http://git-wip-us.apache.org/repos/asf/camel/blob/d8602f26/examples/camel-example-grpc-kubernetes/hello-camel-grpc-client-kubernetes/pom.xml ---------------------------------------------------------------------- diff --git a/examples/camel-example-grpc-kubernetes/hello-camel-grpc-client-kubernetes/pom.xml b/examples/camel-example-grpc-kubernetes/hello-camel-grpc-client-kubernetes/pom.xml index c67edd6..c1717d2 100644 --- a/examples/camel-example-grpc-kubernetes/hello-camel-grpc-client-kubernetes/pom.xml +++ b/examples/camel-example-grpc-kubernetes/hello-camel-grpc-client-kubernetes/pom.xml @@ -115,48 +115,48 @@ </plugins> </build> - <profiles> - <profile> - <id>kubernetes-install</id> + <profiles> + <profile> + <id>kubernetes-install</id> - <build> - <defaultGoal>install</defaultGoal> + <build> + <defaultGoal>install</defaultGoal> - <plugins> + <plugins> - <plugin> - <groupId>io.fabric8</groupId> - <artifactId>fabric8-maven-plugin</artifactId> - <version>3.2.31</version> - <configuration> - <generator> - <config> - <java-exec> - <mainClass>org.apache.camel.example.springboot.grpc.Application</mainClass> - </java-exec> - </config> - </generator> - <enricher> - <config> - <fmp-service> - <name>grpc-client</name> - </fmp-service> - </config> - </enricher> - </configuration> - <executions> - <execution> - <goals> - <goal>resource</goal> - <goal>build</goal> - </goals> - </execution> - </executions> - </plugin> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>fabric8-maven-plugin</artifactId> + <version>3.2.31</version> + <configuration> + <generator> + <config> + <java-exec> + <mainClass>org.apache.camel.example.springboot.grpc.Application</mainClass> + </java-exec> + </config> + </generator> + <enricher> + <config> + <fmp-service> + <name>grpc-client</name> + </fmp-service> + </config> + </enricher> + </configuration> + <executions> + <execution> + <goals> + <goal>resource</goal> + <goal>build</goal> + </goals> + </execution> + </executions> + </plugin> - </plugins> - </build> - </profile> - </profiles> + </plugins> + </build> + </profile> + </profiles> </project> http://git-wip-us.apache.org/repos/asf/camel/blob/d8602f26/examples/camel-example-grpc-kubernetes/hello-camel-grpc-client-kubernetes/src/main/java/org/apache/camel/example/springboot/grpc/CamelGrpcRoute.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-grpc-kubernetes/hello-camel-grpc-client-kubernetes/src/main/java/org/apache/camel/example/springboot/grpc/CamelGrpcRoute.java b/examples/camel-example-grpc-kubernetes/hello-camel-grpc-client-kubernetes/src/main/java/org/apache/camel/example/springboot/grpc/CamelGrpcRoute.java index 95d40f6..864a880 100644 --- a/examples/camel-example-grpc-kubernetes/hello-camel-grpc-client-kubernetes/src/main/java/org/apache/camel/example/springboot/grpc/CamelGrpcRoute.java +++ b/examples/camel-example-grpc-kubernetes/hello-camel-grpc-client-kubernetes/src/main/java/org/apache/camel/example/springboot/grpc/CamelGrpcRoute.java @@ -32,7 +32,7 @@ public class CamelGrpcRoute extends RouteBuilder { public void configure() throws Exception { CamelHelloRequest request = CamelHelloRequest.newBuilder().setName("Camel").build(); - from("timer://foo?period=10000&repeatCount=1").process(new Processor() { + from("timer://foo?period=10000&repeatCount=5").process(new Processor() { @Override public void process(Exchange exchange) throws Exception { http://git-wip-us.apache.org/repos/asf/camel/blob/d8602f26/examples/camel-example-grpc-kubernetes/hello-camel-grpc-server-kubernetes/pom.xml ---------------------------------------------------------------------- diff --git a/examples/camel-example-grpc-kubernetes/hello-camel-grpc-server-kubernetes/pom.xml b/examples/camel-example-grpc-kubernetes/hello-camel-grpc-server-kubernetes/pom.xml index 4616874..16b456b 100644 --- a/examples/camel-example-grpc-kubernetes/hello-camel-grpc-server-kubernetes/pom.xml +++ b/examples/camel-example-grpc-kubernetes/hello-camel-grpc-server-kubernetes/pom.xml @@ -11,9 +11,9 @@ <name>Camel :: Example :: gRPC :: Hello Camel Server Kubernetes</name> <description>An example showing a simple gRPC server running on Kubernetes</description> - <properties> - <main.class>org.apache.camel.examples.grpc.HelloCamelServer</main.class> - </properties> + <properties> + <main.class>org.apache.camel.examples.grpc.HelloCamelServer</main.class> + </properties> <dependencies> <dependency> @@ -86,43 +86,55 @@ <includePluginDependencies>false</includePluginDependencies> </configuration> </plugin> + <plugin> + <!-- Build an executable JAR --> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.4</version> + <configuration> + <archive> + <manifest> + <mainClass>org.apache.camel.examples.grpc.HelloCamelServer</mainClass> + </manifest> + </archive> + </configuration> + </plugin> </plugins> </build> - <profiles> - <profile> - <id>kubernetes-install</id> - - <build> - <defaultGoal>install</defaultGoal> + <profiles> + <profile> + <id>kubernetes-install</id> - <plugins> + <build> + <defaultGoal>install</defaultGoal> - <plugin> - <groupId>io.fabric8</groupId> - <artifactId>fabric8-maven-plugin</artifactId> - <version>3.2.31</version> - <configuration> - <enricher> - <config> - <fmp-service> - <name>grpc-server</name> - </fmp-service> - </config> - </enricher> - </configuration> - <executions> - <execution> - <goals> - <goal>resource</goal> - <goal>build</goal> - </goals> - </execution> - </executions> - </plugin> + <plugins> - </plugins> - </build> - </profile> - </profiles> + <plugin> + <groupId>io.fabric8</groupId> + <artifactId>fabric8-maven-plugin</artifactId> + <version>3.2.31</version> + <configuration> + <enricher> + <config> + <fmp-service> + <name>grpc-server</name> + </fmp-service> + </config> + </enricher> + </configuration> + <executions> + <execution> + <goals> + <goal>resource</goal> + <goal>build</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> </project> http://git-wip-us.apache.org/repos/asf/camel/blob/d8602f26/examples/pom.xml ---------------------------------------------------------------------- diff --git a/examples/pom.xml b/examples/pom.xml index 7a4441b..88e11b7 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -61,6 +61,7 @@ <module>camel-example-google-pubsub</module> <module>camel-example-guice-jms</module> <module>camel-example-groovy</module> + <module>camel-example-grpc-kubernetes</module> <module>camel-example-hazelcast-kubernetes</module> <module>camel-example-hystrix</module> <module>camel-example-java8</module>