jueves, 27 de junio de 2019

Spring Cloud Netflix - Java, Parte 1


https://github.com/jalbertomr/SpringCloudNetflix.git

Componentes Netflix

Eureka                  Registro y Busqueda de Servicios.
Ribbon                  Balanceador de Carga.
Hystrix                  Circuit Breaker.
Zuul                      Ruteador Inteligente

Productor-Consumidor enlace directo


Se crea un servicio productor con eclipse Ide en Java, definiendo el projecto como maven, con un punto de entrada REST.

La estructura del projecto será como:


toma por default el puerto 8080.

La ejecución (spring boot app) que no arroja a la consola

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.1.RELEASE)

2019-06-27 14:53:06.305  INFO 8888 --- [           main] com.bext.SpringBootHolaMundoApplication  : Starting SpringBootHolaMundoApplication on android-ae23f0022eea with PID 8888 (C:\Users\Bext\workspace\employee-producer\target\classes started by Bext in C:\Users\Bext\workspace\employee-producer)
2019-06-27 14:53:06.305  INFO 8888 --- [           main] com.bext.SpringBootHolaMundoApplication  : No active profile set, falling back to default profiles: default
2019-06-27 14:53:06.430  INFO 8888 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@17c1bced: startup date [Thu Jun 27 14:53:06 CDT 2019]; root of context hierarchy
2019-06-27 14:53:09.509  INFO 8888 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2019-06-27 14:53:09.533  INFO 8888 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2019-06-27 14:53:09.533  INFO 8888 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.5
2019-06-27 14:53:09.721  INFO 8888 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-06-27 14:53:09.721  INFO 8888 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3307 ms
2019-06-27 14:53:10.097  INFO 8888 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2019-06-27 14:53:10.113  INFO 8888 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-06-27 14:53:10.113  INFO 8888 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-06-27 14:53:10.113  INFO 8888 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-06-27 14:53:10.113  INFO 8888 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2019-06-27 14:53:10.889  INFO 8888 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@17c1bced: startup date [Thu Jun 27 14:53:06 CDT 2019]; root of context hierarchy
2019-06-27 14:53:11.031  INFO 8888 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/empleado],methods=[GET]}" onto public com.bext.model.Employee com.bext.controllers.TestController.firstPage()
2019-06-27 14:53:11.047  INFO 8888 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-06-27 14:53:11.047  INFO 8888 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-06-27 14:53:11.125  INFO 8888 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-06-27 14:53:11.125  INFO 8888 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-06-27 14:53:11.219  INFO 8888 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-06-27 14:53:11.797  INFO 8888 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-06-27 14:53:11.984  INFO 8888 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2019-06-27 14:53:11.999  INFO 8888 --- [           main] com.bext.SpringBootHolaMundoApplication  : Started SpringBootHolaMundoApplication in 6.589 seconds (JVM running for 8.573)
2019-06-27 14:53:26.958  INFO 8888 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2019-06-27 14:53:26.958  INFO 8888 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2019-06-27 14:53:27.006  INFO 8888 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 33 ms

Accesamos al servicio desde el browser


Creamos una aplicación que consuma el productor anterior desde spring boot java.


Se agrega el archivo aplication.properties con
server.port=8091


Al ejecutar (spring boot app) el consumidor, desde la consola nos arroja el siguiente resultado, su consulta.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.1.RELEASE)

2019-06-27 18:24:11.028  INFO 4908 --- [           main] com.bext.SpringBootHolaMundoApplication  : Starting SpringBootHolaMundoApplication on android-ae23f0022eea with PID 4908 (C:\Users\Bext\workspace\employee-consumer\target\classes started by Bext in C:\Users\Bext\workspace\employee-consumer)
2019-06-27 18:24:11.036  INFO 4908 --- [           main] com.bext.SpringBootHolaMundoApplication  : No active profile set, falling back to default profiles: default
2019-06-27 18:24:11.176  INFO 4908 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1a84f40f: startup date [Thu Jun 27 18:24:11 CDT 2019]; root of context hierarchy
2019-06-27 18:24:12.451  INFO 4908 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Overriding bean definition for bean 'consumerControllerClient' with a different definition: replacing [Generic bean: class [com.bext.controllers.ConsumerControllerClient]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in file [C:\Users\Bext\workspace\employee-consumer\target\classes\com\bext\controllers\ConsumerControllerClient.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=springBootHolaMundoApplication; factoryMethodName=consumerControllerClient; initMethodName=null; destroyMethodName=(inferred); defined in com.bext.SpringBootHolaMundoApplication]
2019-06-27 18:24:14.324  INFO 4908 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8091 (http)
2019-06-27 18:24:14.355  INFO 4908 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2019-06-27 18:24:14.359  INFO 4908 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.5
2019-06-27 18:24:14.598  INFO 4908 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-06-27 18:24:14.598  INFO 4908 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3432 ms
2019-06-27 18:24:15.020  INFO 4908 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2019-06-27 18:24:15.036  INFO 4908 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2019-06-27 18:24:15.036  INFO 4908 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2019-06-27 18:24:15.036  INFO 4908 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2019-06-27 18:24:15.036  INFO 4908 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2019-06-27 18:24:16.223  INFO 4908 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@1a84f40f: startup date [Thu Jun 27 18:24:11 CDT 2019]; root of context hierarchy
2019-06-27 18:24:16.458  INFO 4908 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-06-27 18:24:16.458  INFO 4908 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2019-06-27 18:24:16.567  INFO 4908 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-06-27 18:24:16.567  INFO 4908 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-06-27 18:24:16.692  INFO 4908 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2019-06-27 18:24:17.286  INFO 4908 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-06-27 18:24:17.443  INFO 4908 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8091 (http)
2019-06-27 18:24:17.443  INFO 4908 --- [           main] com.bext.SpringBootHolaMundoApplication  : Started SpringBootHolaMundoApplication in 7.328 seconds (JVM running for 9.564)
com.bext.controllers.ConsumerControllerClient@5fd9b663
{"empId":"1","name":"emp1","designation":"manager","salary":3000.0}




eot

No hay comentarios:

Publicar un comentario