With Spring Cloud - Brixton.M1, random port not registered with Eureka - spring-cloud

With Angel.SR3, assigning server.port: 0 would assign a random port to embedded Tomcat instance and use that port when registering with Eureka (using random instance ID as well in order to run more than one instance of a service on my dev machine).
I want to use the new Spring Cloud Sleuth for automatic tracing so first I just tried using spring-cloud-starter-sleuth at 1.0.0.M1 but trace and span didn't show up in log files when using the logging pattern in the example app. I thought it might be related to the versions of the other libraries that I was picking up with Angel.SR3 so I tried experimenting with Brixton.M1. With Brixton.M1, trace and span are now being set correctly but my service no longer registers its random port with Eureka - port 0 is registered instead. Tomcat DOES come up on a random port, however.
I added a breakpoint in EurekaDiscoveryClientConfiguration.containerPortInitializer() and it is not hit until AFTER the service has registered with Eureka Server in Brixton.M1 and is hit BEFORE service registration in Angel.SR3.
Am I missing something or is this currently broken in Brixton.M1?

This is a known issue that has been fixed in snapshots. Another milestone will come in the next week or so.

Related

How to find port number of a Spring Boot app?

How do I find the port number of my SpringBoot app so I can call it? I already tried setting -Dserver.port=8080 and--server.port=8080 in VM arguments and in src/main/resources/application.properties.
If I try to go to localhost:8080 Chrome says refused to connect. I simply want to be able to connect to my App don't know why Spring Boot made finding which port is being used so challenging.
I'm using Eclipse and the app appears to be running properly from the logs.
This simply printed 0:
#Value("${local.server.port}")
int port;
I've tried these answers none work:
Spring Boot - How to get the running port
Spring boot - how to get running port and ip address How to configure port for a Spring Boot application How to configure port for a Spring Boot application
localhost:<your port> may not respond at all. Make sure you're hitting an endpoint you know is availible like localhost:8080/info. Make sure your app has completly started, it could take serveral minutes.
As #BrianC mentioned make sure your app is actually a web server.
in your springboot main method use below code to detect port of your application
Environment environment =app.run(args).getEnvironment();
System.out.println(environment.getProprty("server.port");
this will tell you actual port where your aplication running .
Value can be found using Spring’s Environment as it represents the environment in which the current application is running.
It can also be used to find other properties in applications like profiles.
#Autowired Environment environment;
String port = environment. getProperty("local.server.port");

Register micro-services using spring-eureka from more than 1 server

I have a set of micro-services which need to communicate to each other.
The total number of micro-services does not fit to single physical server so I need to spread them out among 2 different servers.
My idea (do not know if correct) is to have spring-eureka instance per server to which all services from this particular server register. So:
Services (A,B) register to Eureka on Server 1.
Services (C,D) register to Eureka on Server 2.
After that eureka instances will exchange their knowledge (Peer Awareness).
The questions are:
Does described idea is correct approach? Or rather there should exist just single Eureka instance on single server to which all services from both servers will register (i.e. Eureka exists only on Server1)?
If described idea is correct then as I understand ports 8761 should be opened on Server1 and Server2 to allow communication between "Eurekas"? And the configuration should be as following:
Eureka on Server 1:
eureka.client.serviceUrl.defaultZone: http[s]://server2address:8761/eureka/
Eureka on Server 2:
eureka.client.serviceUrl.defaultZone: http[s]://server1address:8761/eureka/
1) normally you would have a server for each service (A,B,C,D eureka1 and eureka2)
2) eureka.client.serviceUrl.defaultZone is a comma separated list so it is more like "eureka.client.serviceUrl.defaultZone: http[s]://server1address:8761/eureka/,http[s]://server2address:8761/eureka/" for each service
Hope that helps, cheers

Deploy application to wildfly on a certain port

By default, applications in wildfly are deployed to localhost:8080/app. How to deploy application on dedicated port, i.e. open it on localhost:8282 without application name ending?
I need to change the port for certain application, not the default port.
I have not tried this, but AFAICT it should be possible to:
run a single Wildfly instance listening on multiple HTTP ports. This is, in theory at least, possible (ref: https://developer.jboss.org/thread/233414?start=0&tstart=0)
Configure undertow subsystem as a reverse proxy, and proxy your app to the other port/location (ref: http://www.mastertheboss.com/jboss-server/wildfly-8/configuring-a-reverse-proxy-with-undertow). That said, I have never used undertow for a reverse proxy and as such cannot speak for whether this really works.
Once you have done this, you have effectively just turned your Wildfly instance into an overly complex application server and reverse proxy in one. Ultimately however, the app in question would still be running on both ports, but you redirect the traffic using the proxy the way you would like.
The same proxy configuration in an Apache (ref: https://httpd.apache.org/docs/current/mod/mod_proxy.html#forwardreverse or https://www.leaseweb.com/labs/2014/12/tutorial-apache-2-4-transparent-reverse-proxy/) or NGINX (ref: https://www.nginx.com/resources/admin-guide/reverse-proxy/) would be IMHO less complex and better tested in countless production scenarios.

How to define standard port numbers for different apps

We have several enterprise application to deploy on Weblogic server. As you know for each domain we could define specific port, deploy an application on that and clients could access to server application by that port. My question is about the port number standard.
Is there any standard to assign server ports number to different application, if No what is your suggestion ? Is counting method (for example) god ?!! or ...
Thanks for your replies
You can deploy your applications in different managed servers. What you have to do is create a managed server per application under your weblogic domain. During the configuration of the managed server you will be asked to give a port number. After setting the managed server your applications can be deployed on them, using the ports you have specified earlier. More information about the weblogic managed servers can be found in weblogic administration guide.

Can I force Eureka registrations to use an ip address instead of a hostname?

I have a standalone, embedded Eureka server powered by Spring Boot 1.2.0.RELEASE and Spring Cloud 1.0.0.RC1. I see services properly registering themselves in the dashboard, which is great. The status links are using the host name of the box they are running on. Unfortunately, we are using virtual machines and they don't register themselves in DNS, which means that the links are unresolvable. I started looking through the code but was unable to find a way to force the links to use the host's ip address instead. Having a broken dashboard is not the end of the world but I am afraid that once we start using Ribbon or Feign to contact services, those URLs will also use the host name and be unresolvable. Maybe what I am really asking is there a way to force the clients to register with an ip address instead of a host name? Any help is appreciated.
set eureka.instance.preferIpAddress=true as documented here