Initialize

In this phase, the class initializes all of the elements needed to perform the invocations to other microservices, and obtains, with the LRA implementation, the LRAClient that's needed to interact with the LRA coordinator:


@ApplicationScoped
@Path("/footballplayer-market")
public class FootballPlayerMarketREST {

private static final Logger LOG =
Logger.getLogger(FootballPlayerMarketREST.class.getName());

private Client footballPlayerClient;

private Client footballPlayerOfferClient;

private WebTarget footballPlayerTarget;

private WebTarget footballPlayerOfferTarget;

@Inject
private LRAClient lraClient;

@PostConstruct
private void init() {
footballPlayerClient = ClientBuilder.newClient();
footballPlayerOfferClient = ClientBuilder.newClient();
footballPlayerTarget = footballPlayerClient.target(
"http://localhost:8080/footballplayer");
footballPlayerOfferTarget = footballPlayerOfferClient.target(
"http://localhost:8680/footballplayeroffer");
}

@PreDestroy
private void destroy() {
footballPlayerClient.close();
footballPlayerOfferClient.close();
}
...
}

The most important thing to notice is that the LRAClient will be automatically injected into the container, and, using the lra.http.port and lra.http.host properties given upon startup, will automatically connect to the LRA coordinator. Clearly, the URLs relating to the microservices to be invoked should be parameterized so that they are correctly configured according to the execution environment.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset