├── hola-wildflyswarm ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ ├── apache-deltaspike.properties │ │ │ └── beans.xml │ │ └── java │ │ └── com │ │ └── redhat │ │ └── examples │ │ └── wfswarm │ │ └── rest │ │ ├── RestApplication.java │ │ ├── HolaResource.java │ │ ├── BackendDTO.java │ │ ├── BackendCommand.java │ │ └── GreeterResource.java └── pom.xml ├── ribbon-service-account.yml ├── .gitignore ├── hola-springboot ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── HolaSpringbootApplication.java │ │ │ ├── BackendDTO.java │ │ │ ├── HolaRestController.java │ │ │ ├── BackendCommand.java │ │ │ └── GreeterRestController.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── HolaSpringbootApplicationTests.java └── pom.xml ├── hola-dropwizard ├── src │ └── main │ │ ├── resources │ │ └── banner.txt │ │ └── java │ │ └── com │ │ └── redhat │ │ └── examples │ │ └── dropwizard │ │ ├── HolaDropwizardConfiguration.java │ │ ├── resources │ │ ├── HelloSayingFactory.java │ │ ├── HolaRestResource.java │ │ ├── GreeterSayingFactory.java │ │ └── GreeterRestResource.java │ │ ├── api │ │ ├── BackendDTO.java │ │ └── BackendCommand.java │ │ └── HolaDropwizardApplication.java ├── conf │ └── application.yml └── pom.xml ├── pom.xml └── backend ├── src └── main │ ├── webapp │ └── WEB-INF │ │ └── web.xml │ └── java │ └── com │ └── redhat │ └── examples │ └── backend │ ├── ResponseDTO.java │ └── BackendHttpServlet.java └── pom.xml /hola-wildflyswarm/src/main/resources/META-INF/apache-deltaspike.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ribbon-service-account.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: ribbon -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | *.iml 4 | *.log 5 | dependency-reduced-pom.xml 6 | .classpath 7 | .project 8 | .settings 9 | -------------------------------------------------------------------------------- /hola-springboot/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | helloapp.saying=Hola Spring Boot de 2 | #helloapp.saying=Gutten Tag aus 3 | 4 | greeting.saying=Hola Spring Boot 5 | greeting.backendServiceHost=localhost 6 | greeting.backendServicePort=8080 -------------------------------------------------------------------------------- /hola-dropwizard/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | 3 | HolaDropwizard 4 | 5 | ================================================================================ 6 | 7 | -------------------------------------------------------------------------------- /hola-wildflyswarm/src/main/java/com/redhat/examples/wfswarm/rest/RestApplication.java: -------------------------------------------------------------------------------- 1 | package com.redhat.examples.wfswarm.rest; 2 | 3 | import javax.ws.rs.core.Application; 4 | import javax.ws.rs.ApplicationPath; 5 | 6 | @ApplicationPath("/") 7 | public class RestApplication extends Application { 8 | } -------------------------------------------------------------------------------- /hola-dropwizard/conf/application.yml: -------------------------------------------------------------------------------- 1 | 2 | # configurations for our sayingFactory 3 | helloapp: 4 | 5 | saying: ${HELLOAPP_SAYING:-Gutten Tag aus} 6 | 7 | 8 | greeter: 9 | 10 | saying: ${GREETER_SAYING:-Gutten Tag Dropwizard} 11 | host: ${GREETER_BACKEND_HOST:-localhost} 12 | port: ${GREETER_BACKEND_PORT:-8080} 13 | 14 | server: 15 | applicationConnectors: 16 | - type: http 17 | port: 8080 -------------------------------------------------------------------------------- /hola-springboot/src/main/java/com/example/HolaSpringbootApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 6 | 7 | @SpringBootApplication 8 | @EnableConfigurationProperties 9 | public class HolaSpringbootApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(HolaSpringbootApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /hola-springboot/src/test/java/com/example/HolaSpringbootApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.test.context.web.WebAppConfiguration; 6 | import org.springframework.boot.test.SpringApplicationConfiguration; 7 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 8 | 9 | @RunWith(SpringJUnit4ClassRunner.class) 10 | @SpringApplicationConfiguration(classes = HolaSpringbootApplication.class) 11 | @WebAppConfiguration 12 | public class HolaSpringbootApplicationTests { 13 | 14 | @Test 15 | public void contextLoads() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.redhat.microservices 8 | microservices-by-example-source 9 | 1.0 10 | pom 11 | 12 | 13 | hola-springboot 14 | hola-dropwizard 15 | hola-wildflyswarm 16 | backend 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /hola-wildflyswarm/src/main/java/com/redhat/examples/wfswarm/rest/HolaResource.java: -------------------------------------------------------------------------------- 1 | package com.redhat.examples.wfswarm.rest; 2 | 3 | import org.apache.deltaspike.core.api.config.ConfigProperty; 4 | 5 | import javax.enterprise.context.ApplicationScoped; 6 | import javax.inject.Inject; 7 | import javax.ws.rs.Path; 8 | import javax.ws.rs.core.Response; 9 | import javax.ws.rs.GET; 10 | import javax.ws.rs.Produces; 11 | 12 | @Path("/api/hola") 13 | public class HolaResource { 14 | 15 | @Inject 16 | @ConfigProperty(name = "WF_SWARM_SAYING", defaultValue = "Hola") 17 | private String saying; 18 | 19 | @GET 20 | @Produces("text/plain") 21 | public Response doGet() { 22 | return Response.ok(saying + " from WF Swarm").build(); 23 | } 24 | } -------------------------------------------------------------------------------- /hola-wildflyswarm/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | -------------------------------------------------------------------------------- /hola-dropwizard/src/main/java/com/redhat/examples/dropwizard/HolaDropwizardConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.redhat.examples.dropwizard; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import io.dropwizard.Configuration; 5 | import com.redhat.examples.dropwizard.resources.GreeterSayingFactory; 6 | import com.redhat.examples.dropwizard.resources.HelloSayingFactory; 7 | 8 | public class HolaDropwizardConfiguration extends Configuration { 9 | 10 | 11 | private HelloSayingFactory sayingFactory; 12 | private GreeterSayingFactory greeterSayingFactory; 13 | 14 | @JsonProperty("helloapp") 15 | public HelloSayingFactory getSayingFactory() { 16 | return sayingFactory; 17 | } 18 | 19 | @JsonProperty("helloapp") 20 | public void setSayingFactory(HelloSayingFactory sayingFactory) { 21 | this.sayingFactory = sayingFactory; 22 | } 23 | 24 | @JsonProperty("greeter") 25 | public GreeterSayingFactory getGreeterSayingFactory() { 26 | return greeterSayingFactory; 27 | } 28 | 29 | @JsonProperty("greeter") 30 | public void setGreeterSayingFactory(GreeterSayingFactory greeterSayingFactory) { 31 | this.greeterSayingFactory = greeterSayingFactory; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /backend/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | 23 | 24 | BackendHttpServlet 25 | BackendHttpServlet 26 | com.redhat.examples.backend.BackendHttpServlet 27 | 28 | 29 | 30 | 31 | BackendHttpServlet 32 | /api/backend 33 | 34 | 35 | -------------------------------------------------------------------------------- /hola-dropwizard/src/main/java/com/redhat/examples/dropwizard/resources/HelloSayingFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.dropwizard.resources; 18 | 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | import org.hibernate.validator.constraints.NotEmpty; 21 | 22 | /** 23 | * Created by ceposta 24 | */ 25 | public class HelloSayingFactory { 26 | 27 | @NotEmpty 28 | private String saying; 29 | 30 | @JsonProperty 31 | public String getSaying() { 32 | return saying; 33 | } 34 | 35 | @JsonProperty 36 | public void setSaying(String saying) { 37 | this.saying = saying; 38 | } 39 | } -------------------------------------------------------------------------------- /hola-dropwizard/src/main/java/com/redhat/examples/dropwizard/api/BackendDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.dropwizard.api; 18 | 19 | /** 20 | * Created by ceposta 21 | */ 22 | public class BackendDTO { 23 | 24 | private String greeting; 25 | private long time; 26 | private String ip; 27 | 28 | public String getGreeting() { 29 | return greeting; 30 | } 31 | 32 | public void setGreeting(String greeting) { 33 | this.greeting = greeting; 34 | } 35 | 36 | public long getTime() { 37 | return time; 38 | } 39 | 40 | public void setTime(long time) { 41 | this.time = time; 42 | } 43 | 44 | public String getIp() { 45 | return ip; 46 | } 47 | 48 | public void setIp(String ip) { 49 | this.ip = ip; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hola-springboot/src/main/java/com/example/BackendDTO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.example; 18 | 19 | /** 20 | * Created by ceposta 21 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.backend; 18 | 19 | /** 20 | * Created by ceposta 21 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.wfswarm.rest; 18 | 19 | import javax.xml.bind.annotation.XmlRootElement; 20 | 21 | /** 22 | * Created by ceposta 23 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.dropwizard.resources; 18 | 19 | import com.codahale.metrics.annotation.Timed; 20 | 21 | import javax.ws.rs.GET; 22 | import javax.ws.rs.Path; 23 | import java.net.InetAddress; 24 | import java.net.UnknownHostException; 25 | 26 | /** 27 | * Created by ceposta 28 | */ 29 | @Path("/api") 30 | public class HolaRestResource { 31 | 32 | private String saying; 33 | public HolaRestResource(final String saying) { 34 | this.saying = saying; 35 | } 36 | 37 | @Path("/hola") 38 | @GET 39 | @Timed 40 | public String hola() throws UnknownHostException { 41 | String hostname = null; 42 | try { 43 | hostname = InetAddress.getLocalHost().getHostAddress(); 44 | } catch (UnknownHostException e) { 45 | hostname = "unknown"; 46 | } 47 | return saying + " " + hostname; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /hola-dropwizard/src/main/java/com/redhat/examples/dropwizard/resources/GreeterSayingFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.dropwizard.resources; 18 | 19 | import com.fasterxml.jackson.annotation.JsonProperty; 20 | import io.dropwizard.client.JerseyClientConfiguration; 21 | import org.hibernate.validator.constraints.NotEmpty; 22 | 23 | /** 24 | * Created by ceposta 25 | */ 26 | public class GreeterSayingFactory { 27 | 28 | @NotEmpty 29 | private String saying; 30 | 31 | @NotEmpty 32 | private String host; 33 | 34 | @NotEmpty 35 | private int port; 36 | 37 | private JerseyClientConfiguration jerseyClientConfig = new JerseyClientConfiguration(); 38 | 39 | 40 | @JsonProperty("jerseyClient") 41 | public JerseyClientConfiguration getJerseyClientConfig() { 42 | return jerseyClientConfig; 43 | } 44 | 45 | public String getSaying() { 46 | return saying; 47 | } 48 | 49 | public void setSaying(String saying) { 50 | this.saying = saying; 51 | } 52 | 53 | public String getHost() { 54 | return host; 55 | } 56 | 57 | public void setHost(String host) { 58 | this.host = host; 59 | } 60 | 61 | public int getPort() { 62 | return port; 63 | } 64 | 65 | public void setPort(int port) { 66 | this.port = port; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /hola-springboot/src/main/java/com/example/HolaRestController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.example; 18 | 19 | import org.springframework.boot.context.properties.ConfigurationProperties; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RequestMethod; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import java.net.InetAddress; 25 | import java.net.UnknownHostException; 26 | 27 | /** 28 | * Created by ceposta 29 | * { 16 | 17 | public static void main(final String[] args) throws Exception { 18 | new HolaDropwizardApplication().run(args); 19 | } 20 | 21 | @Override 22 | public String getName() { 23 | return "HolaDropwizard"; 24 | } 25 | 26 | @Override 27 | public void initialize(final Bootstrap bootstrap) { 28 | // Enable variable substitution with environment variables 29 | bootstrap.setConfigurationSourceProvider( 30 | new SubstitutingSourceProvider( 31 | bootstrap.getConfigurationSourceProvider(), 32 | new EnvironmentVariableSubstitutor(false) 33 | ) 34 | ); 35 | } 36 | 37 | @Override 38 | public void run(final HolaDropwizardConfiguration configuration, 39 | final Environment environment) { 40 | 41 | // simple hola service 42 | environment.jersey().register(new HolaRestResource(configuration.getSayingFactory().getSaying())); 43 | 44 | 45 | // greeter service 46 | GreeterSayingFactory greeterSayingFactory = configuration.getGreeterSayingFactory(); 47 | Client greeterClient = new JerseyClientBuilder(environment) 48 | .using(greeterSayingFactory.getJerseyClientConfig()) 49 | .build("greeterClient"); 50 | 51 | environment.jersey().register(new GreeterRestResource(greeterSayingFactory.getSaying(), 52 | greeterSayingFactory.getHost(), 53 | greeterSayingFactory.getPort(), greeterClient)); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /backend/src/main/java/com/redhat/examples/backend/BackendHttpServlet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.backend; 18 | 19 | import com.fasterxml.jackson.databind.ObjectMapper; 20 | 21 | import javax.servlet.ServletException; 22 | import javax.servlet.http.HttpServlet; 23 | import javax.servlet.http.HttpServletRequest; 24 | import javax.servlet.http.HttpServletResponse; 25 | import java.io.IOException; 26 | import java.io.PrintWriter; 27 | import java.net.InetAddress; 28 | import java.net.UnknownHostException; 29 | 30 | /** 31 | * Created by ceposta 32 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.dropwizard.resources; 18 | 19 | import com.codahale.metrics.annotation.Timed; 20 | import com.redhat.examples.dropwizard.api.BackendCommand; 21 | import com.redhat.examples.dropwizard.api.BackendDTO; 22 | 23 | import javax.ws.rs.GET; 24 | import javax.ws.rs.Path; 25 | import javax.ws.rs.client.Client; 26 | 27 | /** 28 | * Created by ceposta 29 | */ 30 | @Path("/api") 31 | public class GreeterRestResource { 32 | 33 | private String saying; 34 | private String backendServiceHost; 35 | private int backendServicePort; 36 | private Client client; 37 | 38 | public GreeterRestResource(final String saying, String host, int port, Client client) { 39 | this.saying = saying; 40 | this.backendServiceHost = host; 41 | this.backendServicePort = port; 42 | this.client = client; 43 | } 44 | 45 | @Path("/greeting") 46 | @GET 47 | @Timed 48 | public String greeting() { 49 | String backendServiceUrl = String.format("http://%s:%d", backendServiceHost,backendServicePort); 50 | System.out.println("Sending to: " + backendServiceUrl); 51 | 52 | 53 | BackendDTO backendDTO = client.target(backendServiceUrl) 54 | .path("api") 55 | .path("backend") 56 | .queryParam("greeting", saying) 57 | .request().accept("application/json").get(BackendDTO.class); 58 | 59 | return backendDTO.getGreeting() + " at host: " + backendDTO.getIp(); 60 | } 61 | 62 | @Path("/greeting-hystrix") 63 | @GET 64 | @Timed 65 | public String greetingHystrix() { 66 | BackendCommand command = new BackendCommand(backendServiceHost, backendServicePort).withSaying(saying); 67 | BackendDTO backendDTO = command.execute(); 68 | return backendDTO.getGreeting() + " at host: " + backendDTO.getIp(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /hola-springboot/src/main/java/com/example/BackendCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.example; 18 | 19 | import com.netflix.hystrix.HystrixCommand; 20 | import com.netflix.hystrix.HystrixCommandGroupKey; 21 | import com.netflix.hystrix.HystrixCommandProperties; 22 | import com.netflix.hystrix.HystrixThreadPoolProperties; 23 | import org.springframework.web.client.RestTemplate; 24 | 25 | /** 26 | * Created by ceposta 27 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.dropwizard.api; 18 | 19 | import com.netflix.hystrix.HystrixCommand; 20 | import com.netflix.hystrix.HystrixCommandGroupKey; 21 | import com.netflix.hystrix.HystrixCommandProperties; 22 | import com.netflix.hystrix.HystrixThreadPoolProperties; 23 | 24 | import javax.ws.rs.client.Client; 25 | import javax.ws.rs.client.ClientBuilder; 26 | import javax.ws.rs.core.MediaType; 27 | 28 | /** 29 | * Created by ceposta 30 | */ 31 | public class BackendCommand extends HystrixCommand { 32 | 33 | private String host; 34 | private int port; 35 | private String saying; 36 | 37 | public BackendCommand(String host, int port) { 38 | super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("wildflyswarm.backend")) 39 | .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter() 40 | .withCoreSize(10) 41 | .withMaxQueueSize(-1)) 42 | .andCommandPropertiesDefaults(HystrixCommandProperties.Setter() 43 | .withCircuitBreakerEnabled(true) 44 | .withCircuitBreakerRequestVolumeThreshold(5) 45 | .withMetricsRollingStatisticalWindowInMilliseconds(5000) 46 | )) 47 | ; 48 | this.host = host; 49 | this.port = port; 50 | } 51 | 52 | public BackendCommand withSaying(String saying) { 53 | this.saying = saying; 54 | return this; 55 | } 56 | 57 | @Override 58 | protected BackendDTO run() throws Exception { 59 | String backendServiceUrl = String.format("http://%s:%d", host, port); 60 | System.out.println("Sending to: " + backendServiceUrl); 61 | 62 | Client client = ClientBuilder.newClient(); 63 | return client.target(backendServiceUrl) 64 | .path("api") 65 | .path("backend") 66 | .queryParam("greeting", saying) 67 | .request(MediaType.APPLICATION_JSON_TYPE).get(BackendDTO.class); 68 | 69 | } 70 | 71 | @Override 72 | protected BackendDTO getFallback() { 73 | BackendDTO rc = new BackendDTO(); 74 | rc.setGreeting("Greeting fallback!"); 75 | rc.setIp("127.0.0,1"); 76 | rc.setTime(System.currentTimeMillis()); 77 | return rc; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /hola-wildflyswarm/src/main/java/com/redhat/examples/wfswarm/rest/BackendCommand.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.wfswarm.rest; 18 | 19 | import com.netflix.hystrix.HystrixCommand; 20 | import com.netflix.hystrix.HystrixCommandGroupKey; 21 | import com.netflix.hystrix.HystrixCommandProperties; 22 | import com.netflix.hystrix.HystrixThreadPoolProperties; 23 | 24 | import javax.ws.rs.client.Client; 25 | import javax.ws.rs.client.ClientBuilder; 26 | import javax.ws.rs.core.MediaType; 27 | 28 | /** 29 | * Created by ceposta 30 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.example; 18 | 19 | import org.springframework.boot.context.properties.ConfigurationProperties; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RequestMethod; 22 | import org.springframework.web.bind.annotation.RestController; 23 | import org.springframework.web.client.RestTemplate; 24 | 25 | /** 26 | * Created by ceposta 27 | * 2 | 3 | 4.0.0 4 | 5 | com.redhat.microservices 6 | backend 7 | 1.0 8 | war 9 | 10 | 11 | 12 | 9.3.7.v20160115 13 | 8080 14 | 3.5 15 | 2.6 16 | 2.5 17 | 2.6.3 18 | 2.2.98 19 | 20 | 21 | fabric8/tomcat-8.0 22 | ${fabric8.dockerUser}${project.artifactId}:${project.version} 23 | rootWar 24 | 8778 25 | ${jetty.http.port} 26 | 27 | 28 | 29 | fabric8/ 30 | ${project.artifactId} 31 | 80 32 | ${jetty.http.port} 33 | LoadBalancer 34 | 35 | 36 | 37 | 38 | javax.servlet 39 | servlet-api 40 | ${servlet-version} 41 | 42 | 43 | com.fasterxml.jackson.core 44 | jackson-databind 45 | ${jackson-version} 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.apache.maven.plugins 53 | maven-war-plugin 54 | ${maven-war-plugin.version} 55 | true 56 | 57 | 58 | org.eclipse.jetty 59 | jetty-maven-plugin 60 | ${jetty-maven-plugin.version} 61 | 62 | 63 | 64 | ${jetty.http.port} 65 | 66 | 67 | 68 | 69 | io.fabric8 70 | fabric8-maven-plugin 71 | 2.2.100 72 | 73 | 74 | json 75 | generate-resources 76 | 77 | json 78 | 79 | 80 | 81 | attach 82 | package 83 | 84 | attach 85 | 86 | 87 | 88 | 89 | 90 | 91 | io.fabric8 92 | docker-maven-plugin 93 | 94 | 95 | 96 | 97 | ${docker.image} 98 | 99 | ${docker.from} 100 | 101 | ${docker.assemblyDescriptorRef} 102 | 103 | 104 | -javaagent:/opt/tomcat/jolokia-agent.jar=host=0.0.0.0,port=8778 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | f8-build 117 | 118 | clean install docker:build fabric8:json 119 | 120 | 121 | 122 | f8-deploy 123 | 124 | clean install docker:build docker:push fabric8:json fabric8:apply 125 | 126 | 127 | true 128 | Always 129 | 130 | 131 | 132 | f8-local-deploy 133 | 134 | clean install docker:build fabric8:json fabric8:apply 135 | 136 | 137 | true 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /hola-wildflyswarm/src/main/java/com/redhat/examples/wfswarm/rest/GreeterResource.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.redhat.examples.wfswarm.rest; 18 | 19 | import com.netflix.client.config.DefaultClientConfigImpl; 20 | import com.netflix.client.config.IClientConfig; 21 | import com.netflix.loadbalancer.ILoadBalancer; 22 | import com.netflix.loadbalancer.LoadBalancerBuilder; 23 | import com.netflix.loadbalancer.Server; 24 | import com.netflix.loadbalancer.ServerList; 25 | import com.netflix.loadbalancer.reactive.LoadBalancerCommand; 26 | import com.netflix.loadbalancer.reactive.ServerOperation; 27 | import io.fabric8.kubeflix.ribbon.KubernetesServerList; 28 | import org.apache.deltaspike.core.api.config.ConfigProperty; 29 | import rx.Observable; 30 | 31 | import javax.inject.Inject; 32 | import javax.ws.rs.GET; 33 | import javax.ws.rs.Path; 34 | import javax.ws.rs.client.Client; 35 | import javax.ws.rs.client.ClientBuilder; 36 | import javax.ws.rs.core.MediaType; 37 | import java.net.HttpURLConnection; 38 | import java.net.URL; 39 | import java.util.Arrays; 40 | 41 | /** 42 | * Created by ceposta 43 | * builder() 118 | .withLoadBalancer(loadBalancer) 119 | .build() 120 | .submit(new ServerOperation() { 121 | @Override 122 | public Observable call(Server server) { 123 | String backendServiceUrl = String.format("http://%s:%d", server.getHost(), server.getPort()); 124 | System.out.println("Sending to: " + backendServiceUrl); 125 | 126 | Client client = ClientBuilder.newClient(); 127 | return Observable.just(client.target(backendServiceUrl) 128 | .path("api") 129 | .path("backend") 130 | .queryParam("greeting", saying) 131 | .request(MediaType.APPLICATION_JSON_TYPE).get(BackendDTO.class)); 132 | } 133 | }).toBlocking().first(); 134 | return backendDTO.getGreeting() + " at host: " + backendDTO.getIp(); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /hola-springboot/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.redhat.examples 6 | hola-springboot 7 | 1.0 8 | jar 9 | 10 | hola-springboot 11 | Demo project for Spring Boot 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.3.3.RELEASE 17 | 18 | 19 | 20 | 21 | 1.8 22 | UTF-8 23 | 2.2.98 24 | 1.5.1 25 | 2.1.2 26 | 1.0.15 27 | 28 | 29 | artifact 30 | docker.io/fabric8/java-jboss-openjdk8-jdk:1.0.10 31 | fabric8/${project.artifactId}:${project.version} 32 | 8080 33 | 8778 34 | 35 | 36 | 37 | icons/spring-boot 38 | /health 39 | 8080 40 | 5 41 | 30 42 | 8080 43 | hola-springboot 44 | 80 45 | LoadBalancer 46 | ribbon 47 | backend 48 | 80 49 | true 50 | 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-web 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-actuator 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-starter-test 64 | test 65 | 66 | 67 | com.netflix.hystrix 68 | hystrix-core 69 | ${hystrix.version} 70 | 71 | 72 | com.netflix.hystrix 73 | hystrix-metrics-event-stream 74 | ${hystrix.version} 75 | 76 | 77 | com.netflix.ribbon 78 | ribbon-core 79 | ${ribbon.version} 80 | 81 | 82 | com.netflix.ribbon 83 | ribbon-loadbalancer 84 | ${ribbon.version} 85 | 86 | 87 | io.fabric8.kubeflix 88 | ribbon-discovery 89 | ${kubeflix.version} 90 | 91 | 92 | 93 | 94 | 95 | 96 | org.springframework.boot 97 | spring-boot-maven-plugin 98 | 99 | 100 | io.fabric8 101 | docker-maven-plugin 102 | 0.14.2 103 | 104 | 105 | 106 | ${docker.image} 107 | 108 | ${docker.from} 109 | 110 | /app 111 | ${docker.assemblyDescriptorRef} 112 | 113 | 114 | ${project.artifactId}-${project.version}.war 115 | -Djava.security.egd=/dev/./urandom 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | io.fabric8 124 | fabric8-maven-plugin 125 | 2.2.100 126 | 127 | 128 | json 129 | generate-resources 130 | 131 | json 132 | 133 | 134 | 135 | attach 136 | package 137 | 138 | attach 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | f8-build 149 | 150 | clean install docker:build fabric8:json 151 | 152 | 153 | 154 | f8-deploy 155 | 156 | clean install docker:build docker:push fabric8:json fabric8:apply 157 | 158 | 159 | true 160 | Always 161 | 162 | 163 | 164 | f8-local-deploy 165 | 166 | clean install docker:build fabric8:json fabric8:apply 167 | 168 | 169 | true 170 | 171 | 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /hola-wildflyswarm/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | com.redhat.examples.wfswarm 5 | hola-wildflyswarm 6 | war 7 | 1.0 8 | 9 | 10 | 11 | UTF-8 12 | 1.0.0.Beta7 13 | 1.5.3 14 | 1.8 15 | 1.8 16 | 2.2.98 17 | 1.5.1 18 | 2.1.2 19 | 1.0.15 20 | 21 | 22 | 23 | 0.14.2 24 | fabric8/java-jboss-openjdk8-jdk:1.0.10 25 | fabric8/${project.artifactId}:${project.version} 26 | 8080 27 | 8778 28 | 29 | 30 | 31 | 32 | /api/hola 33 | 8080 34 | 5 35 | 30 36 | hola-wildflyswarm 37 | 80 38 | 8080 39 | LoadBalancer 40 | msa 41 | icons/java 42 | ribbon 43 | 44 | true 45 | backend 46 | 80 47 | true 48 | 49 | 50 | 51 | 52 | 53 | org.wildfly.swarm 54 | bom 55 | ${version.wildfly-swarm} 56 | pom 57 | import 58 | 59 | 60 | org.jboss.spec 61 | jboss-javaee-6.0 62 | 3.0.3.Final 63 | pom 64 | import 65 | 66 | 67 | 68 | 69 | 70 | org.jboss.spec.javax.servlet 71 | jboss-servlet-api_3.0_spec 72 | provided 73 | 74 | 75 | org.jboss.spec.javax.ws.rs 76 | jboss-jaxrs-api_1.1_spec 77 | provided 78 | 79 | 80 | org.wildfly.swarm 81 | jaxrs-cdi 82 | 83 | 84 | org.wildfly.swarm 85 | monitor 86 | 87 | 88 | org.wildfly.swarm 89 | ribbon 90 | 91 | 92 | org.apache.deltaspike.core 93 | deltaspike-core-api 94 | ${deltaspike.version} 95 | 96 | 97 | org.apache.deltaspike.core 98 | deltaspike-core-impl 99 | ${deltaspike.version} 100 | 101 | 102 | com.netflix.hystrix 103 | hystrix-core 104 | ${hystrix.version} 105 | 106 | 107 | com.netflix.hystrix 108 | hystrix-metrics-event-stream 109 | ${hystrix.version} 110 | 111 | 112 | io.fabric8.kubeflix 113 | ribbon-discovery 114 | ${kubeflix.version} 115 | 116 | 117 | 118 | 119 | 120 | hola-wildflyswarm 121 | 122 | 123 | maven-war-plugin 124 | 2.6 125 | 126 | false 127 | 128 | 129 | 130 | org.wildfly.swarm 131 | wildfly-swarm-plugin 132 | ${version.wildfly-swarm} 133 | 134 | 135 | 136 | package 137 | 138 | 139 | 140 | 141 | 142 | / 143 | 144 | 145 | 146 | 147 | io.fabric8 148 | docker-maven-plugin 149 | ${docker.maven.plugin.version} 150 | 151 | 152 | 153 | ${docker.image} 154 | 155 | ${docker.from} 156 | 157 | /app 158 | 159 | ${project.artifactId} 160 | 161 | 162 | ${project.build.directory}/${project.build.finalName}-swarm.jar 163 | / 164 | 165 | 166 | 167 | 168 | 169 | ${project.build.finalName}-swarm.jar 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | io.fabric8 178 | fabric8-maven-plugin 179 | 2.2.100 180 | 181 | 182 | json 183 | generate-resources 184 | 185 | json 186 | 187 | 188 | 189 | attach 190 | package 191 | 192 | attach 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | f8-build 204 | 205 | clean install docker:build fabric8:json 206 | 207 | 208 | 209 | f8-deploy 210 | 211 | clean install docker:build docker:push fabric8:json fabric8:apply 212 | 213 | 214 | true 215 | Always 216 | 217 | 218 | 219 | f8-local-deploy 220 | 221 | clean install docker:build fabric8:json fabric8:apply 222 | 223 | 224 | true 225 | 226 | 227 | 228 | 229 | -------------------------------------------------------------------------------- /hola-dropwizard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 3.0.0 7 | 8 | 9 | com.redhat.examples.dropwizard 10 | hola-dropwizard 11 | 1.0 12 | jar 13 | 14 | HolaDropwizard 15 | 16 | 17 | 18 | UTF-8 19 | UTF-8 20 | 0.9.2 21 | 2.2.98 22 | com.redhat.examples.dropwizard.HolaDropwizardApplication 23 | 1.5.1 24 | 2.1.2 25 | 1.0.15 26 | 27 | 28 | 29 | artifact-with-dependencies 30 | docker.io/fabric8/java-jboss-openjdk8-jdk:1.0.10 31 | fabric8/${project.artifactId}:${project.version} 32 | 8778 33 | 34 | 35 | /api/hola 36 | 8080 37 | 5 38 | 30 39 | ${project.artifactId} 40 | 80 41 | 8080 42 | LoadBalancer 43 | msa 44 | dropwizard 45 | ribbon 46 | 47 | backend 48 | 80 49 | 50 | true 51 | 52 | 53 | 54 | 55 | 56 | 57 | io.dropwizard 58 | dropwizard-bom 59 | ${dropwizard.version} 60 | pom 61 | import 62 | 63 | 64 | 65 | 66 | 67 | 68 | io.dropwizard 69 | dropwizard-core 70 | 71 | 72 | io.dropwizard 73 | dropwizard-client 74 | 75 | 76 | com.netflix.hystrix 77 | hystrix-core 78 | ${hystrix.version} 79 | 80 | 81 | com.netflix.hystrix 82 | hystrix-metrics-event-stream 83 | ${hystrix.version} 84 | 85 | 86 | com.netflix.ribbon 87 | ribbon-core 88 | ${ribbon.version} 89 | 90 | 91 | com.netflix.ribbon 92 | ribbon-loadbalancer 93 | ${ribbon.version} 94 | 95 | 96 | io.fabric8.kubeflix 97 | ribbon-discovery 98 | ${kubeflix.version} 99 | 100 | 101 | 102 | 103 | 104 | 105 | org.codehaus.mojo 106 | exec-maven-plugin 107 | 108 | com.redhat.examples.dropwizard.HolaDropwizardApplication 109 | 110 | server 111 | conf/application.yml 112 | 113 | 114 | 115 | 116 | maven-shade-plugin 117 | 2.4.1 118 | 119 | true 120 | 121 | 122 | 123 | ${mainClass} 124 | 125 | 126 | 127 | 128 | 129 | *:* 130 | 131 | META-INF/*.SF 132 | META-INF/*.DSA 133 | META-INF/*.RSA 134 | 135 | 136 | 137 | 138 | 139 | 140 | package 141 | 142 | shade 143 | 144 | 145 | 146 | 147 | 148 | maven-jar-plugin 149 | 2.6 150 | 151 | 152 | 153 | true 154 | ${mainClass} 155 | 156 | 157 | 158 | 159 | 160 | maven-compiler-plugin 161 | 3.3 162 | 163 | 1.7 164 | 1.7 165 | 166 | 167 | 168 | maven-source-plugin 169 | 2.4 170 | 171 | 172 | attach-sources 173 | 174 | jar 175 | 176 | 177 | 178 | 179 | 180 | maven-javadoc-plugin 181 | 2.10.3 182 | 183 | 184 | attach-javadocs 185 | 186 | jar 187 | 188 | 189 | 190 | 191 | 192 | io.fabric8 193 | docker-maven-plugin 194 | 0.14.2 195 | 196 | 197 | 198 | ${docker.image} 199 | 200 | ${docker.from} 201 | /app/run-java.sh server /app/application.yml 202 | 203 | /app 204 | 205 | ${project.artifactId} 206 | 207 | 208 | ${project.build.directory}/${project.artifactId}-${project.version}.jar 209 | / 210 | 211 | 212 | ${basedir}/conf/application.yml 213 | / 214 | 215 | 216 | 217 | 218 | 219 | ${project.artifactId}-${project.version}.jar 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | io.fabric8 228 | fabric8-maven-plugin 229 | 2.2.100 230 | 231 | 232 | json 233 | generate-resources 234 | 235 | json 236 | 237 | 238 | 239 | attach 240 | package 241 | 242 | attach 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | maven-project-info-reports-plugin 254 | 2.8.1 255 | 256 | false 257 | false 258 | 259 | 260 | 261 | maven-javadoc-plugin 262 | 2.10.3 263 | 264 | 265 | 266 | 267 | 268 | 269 | f8-build 270 | 271 | clean install docker:build fabric8:json 272 | 273 | 274 | 275 | f8-deploy 276 | 277 | clean install docker:build docker:push fabric8:json fabric8:apply 278 | 279 | 280 | true 281 | Always 282 | 283 | 284 | 285 | f8-local-deploy 286 | 287 | clean install docker:build fabric8:json fabric8:apply 288 | 289 | 290 | true 291 | 292 | 293 | 294 | 295 | --------------------------------------------------------------------------------