2

I'm investigating spring-cloud and I've set up two microservices "offers" and "customers" as eureka clients.

The customers app has:

@Data
public class Customer extends ResourceSupport {
    private Long customerId;
    private String name;
}

@RestController
@RequestMapping("/customers")
@ExposesResourceFor(Customer.class)
public class CustomersController {
    ...
}

and the offers app has:

@Data
public class Offer extends ResourceSupport {
    private final Long offerId;
    private final Long priceI;
    private final Customer customer;
}

@RestController
@RequestMapping("/offers")
@ExposesResourceFor(Offer.class)
public class OfferController {
    ...
}

How would I organize the code so that you can add a Customer link to the Offer instances? Autowiring an EntityLink would of course not work since the two controllers live in separate apps.

Would it be reasonable to create interfaces for all the controllers with the @RequestMapping on them and shared the inerfaces in all apps so that you could use e.g. Link link = linkTo(methodOn(OfferController.class).getOffer(2L)).withSelfRel();?

James
  • 11,654
  • 6
  • 52
  • 81
  • If the the offer service gets the customer from the customer service, then you already have the link. If not, then either the offer service is not a microservice or the two services shouldn't be separated in the first place. – a better oliver Sep 20 '15 at 10:17

1 Answers1

1

Depending on how much method needs to be linked I would construct the links manually or go with sharing api-s between apps and building links from those descriptors. I wouldn't introduce a dependency for a few links.

The more interesting question is what are you planning to set as host of the link? The actual host or the eureka id of the service? I recommend setting the id of the service and then setting up a zuul instance and deal with loadbalancing and proxying in that.

P.S: When linking services i always found myself in trouble when linking them too much. Deployment speed and resiliency can greatly suffer.

Ákos Ratku
  • 1,421
  • 12
  • 14
  • The idea is to use the eureka id in the URLs like `http://OFFERS/offers/1`. Whenever possible I'd like to avoid building the links manually. What do you exactly mean with "sharing api-s between apps and building links from those descriptors"? – James Sep 10 '15 at 07:24
  • The same as you when you mention shared interfaces. – Ákos Ratku Sep 10 '15 at 08:12
  • 1
    Sharing interfaces with `@RequestMapping` has another advantage: I just discovered that you can create `@FeignClient`s from those interfaces as well (see [here](http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-inheritance)). – James Sep 10 '15 at 11:30
  • Yes, you can use `@RequestMapping` , but it behaves a little different than on a controller method. E.g: You need to specify requestmethod no matter what. – Ákos Ratku Sep 10 '15 at 11:34