Groovy services
Martini supports the use of Groovy services for building applications. As the name implies, these services are written using Groovy. And put simply, Groovy services refer to Groovy methods.
Groovy services are ideal for creating low-level instructions. In terms of code, Groovy offers great flexibility – what you can't do in Gloop, you can most likely do in Groovy. The caveat, however, is that you must be familiar with programming concepts and the language itself.
You can write Groovy services in the form of Groovy scripts or Groovy methods within Groovy classes.
Here's a sample Groovy class. When called, the sayHello()
method prints Hello, world!
to the console. The
sayHello(String)
method, on the other hand, prints Hello, $name!
to the console where the name
argument
substitutes $name
in the GString
.
1 2 3 4 5 |
|
Here's a sample Groovy script. It prints Hello, world!
to the console when run.
1 |
|
Like services, Groovy services can use functions which help make applications easier to build. For example sending a JMS message can be done simply by:
1 2 3 |
|
Examples
Martini comes bundled with an examples
package that contains many code
snippets and working services to help get you started, including Groovy code samples.