Skip to content

Service

Purpose

List and perform request/response exchanges with deployed Platform 6 services.

Methods

Binding name: p6.service


post

Sends the provided common message to the named service destination endpoint. This method is fire and forget. I.e. It does not wait for a response.

Syntax

void p6.service.post(String destination, Map cmMap)
Parameter: cmMap
Example
p6.service.post("platform6.echo", cm)

Sends the provided common message to the named service destination endpoint and waits indefinitely for a response which is returned as a Map.

Syntax

Map p6.service.request(String destination, Map cmMap)
Parameter: cmMap
Example
def cmResponse = p6.service.request("platform6.echo", cm)
println cmResponse

request

Sends the provided common message to the named service destination endpoint and waiting for up to timeOut time units for a response. Any response is returned as a Map.

Syntax

Map p6.service.request(String destination, Map cmMap, long timeOut, TimeUnit tu)
Parameter: cmMap
Example
import java.util.concurrent.TimeUnit

def cmResponse = p6.service.request("platform6.scripts", cm, 5, TimeUnit.SECONDS)
println cmResponse

request

Sends the provided common message to the named service destination endpoint and waits indefinitely for a response which is returned as a Map via the supplied asynchronous callback.

Syntax

void p6.service.request(String destination, Map cmMap, Closure cb)
Parameter: cmMap

Info

The Callback will receive one of two parameters in the following order (CommonMessageMap, Exception).

Example
p6.service.request("platform6.scripts", cm, {
    cmr, e ->
        println cmr
        if( null != e) throw e
})

sleep 2000

list

Returns a List of all deployed Platform 6 services attached to the common message bus represented as destination names.

Syntax

List p6.service.list()
Example
p6.service.list().each() {
  println "${it}: " + p6.service.getServiceStatus(it)
}

getServiceStatus

Get the service’s status.

Syntax

String p6.service.getServiceStatus( String serviceId )

Info

The status can be: SERVICE_STATE_STARTED, SERVICE_STATE_STARTED_RESTART (if the configuration has changed) and SERVICE_STATE_STOPPED.

Example
println p6.service.getServiceStatus("routes")

startService

Start the serviceId service.

Syntax

void p6.service.startService( String serviceId )
Example
p6.service.startService("routes")

stopService

Stop the serviceId service.

Syntax

void p6.service.stopService( String serviceId )
Example
p6.service.stopService("routes")

restartService

Restart the serviceId service.

Syntax

void p6.service.restartService( String serviceId )
Example
p6.service.restartService("routes")

Parameters

Common Message Maps

The Common Message is the single unit of exchange between Platform 6 service. The common message is represent by a Groovy Map when using the service DSL:

Example

def cm = [
    headers: [
        hello: 'world',
        'platform6.request.user': 'admin'
    ],
    attachments: [
        [
            headers: [
                name: 'body',
                type: 'text/plain'
            ],
            bytes: 'This is the content of the attachment'.getBytes()
        ]
    ]
]
The map contains a headers Map and an attachments List. The attachments List can contain a headers Map and a bytes content.

Both headers and attachments are optional.

Tip

For more information, please refer to the Common Message Bus API Guide.