Running Snoop and registering our service

First, we need to download Snoop Service, which is available as a .war file, and deploy it onto Payara Micro with our sample service, packaged as .war.

The latest version of Snoop Service is 1.3.4 and it available to download from http://central.maven.org/maven2/eu/agilejava/snoop-service/1.3.4/snoop-service-1.3.4.war

Then, we are going to implement a modified version of our Temperature service. We'll start by adding the Snoop artifact dependency, as follows:

<dependency>
<groupId>eu.agilejava</groupId>
<artifactId>snoop</artifactId>
<version>1.3.4</version>
</dependency>

The project structure for the Temperature service is as follows. We'll have an application configuration class, WeatherMicroService, a service implementation ;TemperatureResource, and a Snoop configuration file, snoop.yml:

The application configuration of the deployed service will be changed a little bit to contain the Snoop-specific @EnableSnoopClient annotation. This annotation enables a web application to act as a Snoop client and it helps to register our application as a service under the Snoop Service Registry. serviceName is the unique identifier for this service when it is registered with Snoop Service:

@EnableSnoopClient(serviceName = "weatherSnoop")
@ApplicationPath("/weather")
public class WeatherMicroService extends Application {
}

The TemperatureResource class implementation would be the same as we had in the previous chapter, Chapter 2Creating your first Microservice. The Snoop configuration can either be done in the following order, with the priority of system properties, environment variables, or a provided .YML file. We used the following .YML file as our service registration configuration:

snoop:
host: http://localhost
port: 8080
serviceRoot: weather-snoop-service/weather
snoopService: localhost:8080/snoop-service/

After wrapping up the implementation, it's time to deploy it onto Payara Micro, along with the Snoop Service:

java -jar /path/to/payara-micro.jar --deploy /path/to/weather-snoop-service.war --deploy /path/to/snoop-service-1.3.4.war

After deployment, the URL for the dashboard of Snoop service will be  http://localhost:8080/snoop-service, which lists all registered services. As you can see, our weatherSnoop service got registered with its home URL:

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

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