Skip to content

Writing Services in Trooper

regunathb edited this page Dec 18, 2012 · 11 revisions

This page describes features of the Trooper Service Profile and steps to develop, deploy, orchestrate and monitor service execution.

Trooper Service Profile

Service is one of the supported runtime profiles in Trooper. This means the following to its users:

  • Provision for modular development, testing and deployment of services and optionally orchestration using the profile's features and supporting tools.
  • Life-cycle management of services, configuration refresh using administrative console(s).
  • Compile-and-run support for all service profile features - does not require any packaging for deployment and testing thereby saving development time, providing for easier debugging (via standard break-points in IDEs)
  • Implementation of Convention-Over-Configuration practices to ease development, deployment
  • Integration with Trooper libraries for Event publishing, JMX notifications, Data transformation to XML and JSON.

Implement and configure a service

A Trooper service, by definition, is stateless abstraction of functionality that follows a request-response interaction model. The Request and Response objects define the service vocabulary and the service interface provides a single standard, known method for invocation.

Service implementations are required to follow these guidelines:

  • Define the service vocabulary i.e. request-response objects. The preferred way to do this in Trooper is to define these as XML schemas (XSD files). The XSD files are compiled to produce Java representations of the request-response objects.
  • Create a project (optional) to contain the service vocabulary files i.e. XSD files. Check the Trooper example-models. This project, when built, produces the Java equivalents for the schema defined objects.
  • Write a POJO that implements org.trpr.platform.servicefw.spi.Service interface. Alternatively, extend org.trpr.platform.servicefw.impl.SimpleAbstractServiceImpl and benefit from features like monitoring. See org.trpr.example.service.greeting.SimpleGreetingService for example. Sample services are available in Trooper example-services
  • Configure the service as a Spring bean in a file by name spring-services-config.xml. Bean id follows the naming convention : <service name>_<major version>.<minor version> Snippet from example service configuration is shown below:
<beans>
    <!-- The reference implementation services -->
    <bean id="simpleGreetingService_1.0" class="org.trpr.example.service.greeting.SimpleGreetingService">
        <property name="serviceContext" ref="serviceContext" />
    </bean>	
</beans>

The serviceContext bean referenced here (and other common service framework beans) are defined in /serviceframework-core/src/main/resources/packaged/common-spring-services-config.xml and loaded from classpath during Trooper service profile runtime start up.

Testing a service