phoenixnap / springmvc-raml-plugin

Spring MVC - RAML Spec Synchroniser Plugin. A Maven plugin designed to Generate Server & Client code in Spring from a RAML API descriptor and conversely, a RAML API document from the SpringMVC Server implementation.
Apache License 2.0
136 stars 84 forks source link

Service Discovery Support ? #271

Closed GuangmingLuo closed 5 years ago

GuangmingLuo commented 6 years ago

Hi,

Within the client-side code generated by this plugin, user has to specify the baseUrl and this baseUrl must be IP+PORT, because there is "builder.build". In this case, we can't set this baseUrl to a application name, which can be used by service discovery. RestTemplate used in the code is perfect for service discovery. Why doesn't the code support that ? Can this feature be added ?

I am looking forward to your reply. Thanks.

BR

GhaTMA commented 5 years ago

+1

stojsavljevic commented 5 years ago

Hi,

Thanks for reaching us.

After you set client.url property in your application's properties file it will be translated to baseUrl property in generated client. It needs to be http url but it doesn't require port. Isn't that enough to support service discovery? If not, how does your url looks like and how would you like to be the method's body of generated client? What about SpringFeignClientInterfaceRule?

GuangmingLuo commented 5 years ago

Hi, Great !Thanks for your reply.

I have tried to set base-url= http://{my_service_name}, it works!!! I didn't know that port is not a must requirement.

In this case, as long as you have registered your target server to Consul or Eureka, you may simply set base-url like this: base-url= http://{my_service_name} . And add @LoadBalance to RestTemplate initialization. Service discovery works.

stojsavljevic commented 5 years ago

Cool.

Have you tried to generate feign client (SpringFeignClientInterfaceRule)?

Can we close this issue?

GuangmingLuo commented 5 years ago

Hi, I haven't tried yet. Can you show an example to use this rule ? And which version should be used ?

And yes, you may close this issue.

stojsavljevic commented 5 years ago

I've just discovered 2 issues with FegnClient generation. I'm addressing them in #284. Hopefully, it will be done soon and I will provide an example.