Skip to content

Toro Cloud Dev Center

Redis Pub/Sub listener endpoint

The Redis Pub/Sub listener endpoint enables developers to write applications that react to messages received via a channel managed by Redis.


General configuration

Property Default Description
Name (required) The name of the endpoint.
Service (required) The service to execute when the endpoint is triggered.
Run As Anonymous The user to run the service in behalf of. This is logged to Tracker.
Document Type <Name of endpoint type> The document type to be used when adding documents to Tracker as this endpoint is triggered.
Auto Start true Whether or not to automatically start the endpoint upon package startup.
Log To Tracker false Flag determining whether executions should be logged to Tracker.
Replicated true If this endpoint is configured on a Martini instance that's running in a cluster, replicated will determine whether to run the endpoint on all instances, or only the elected leader node in the cluster. When this is checked, all instances will run the endpoint. When it's unchecked, only the leader node will run the endpoint.

Redis Pub/Sub listener-specific configuration

Properties Default Description
Connection Name (required) Name of the Redis database connection.
Channel (optional) Name of the channel this endpoint should listen to. If this is specified, the patterns list must be empty.
Patterns (optional) A list of Redis patterns that this endpoint should listen to. If a list of patterns is specified, the channel name must be empty.
Ad hoc message publishing

Redis Pub/Sub messages can be sent by:

  • (1) Clicking on the envelope icon next to the Channel text field in the Redis endpoint editor; or
  • (2) Right-clicking on a Redis listener endpoint and then selecting Send Redis Channel Message. This prompts a dialog where you can enter a channel name, and the message you would like to send.

Send Redis Message dialog


When the endpoint is triggered, the following variables are exposed to the configured service:

General parameters

Name Type Description
$trackerId java.lang.String The Tracker document internal ID. If the endpoint was configured to not track, this value will be null.
$tracker io.toro.martini.tracker.Tracker The Tracker object. If the endpoint was configured to not track, this value will be null.
martiniPackage MartiniPackage The Martini package that contains the endpoint.
parameters java.util.Map A map containing all the endpoint specific parameters.
properties java.util.Map A map containing containing all the properties associated with the endpoint.

Redis Pub/Sub listener-specific parameters

Name Type Description
databaseName java.lang.String The name of the Redis database connection where the message was received from.
channel java.lang.String The name of the channel that the message was sent to.
pattern java.lang.String The matching pattern that triggered this endpoint to receive the message.
message java.lang.String The content of the message.
content java.lang.String Alias for message.


Gloop as service

Consider this application using Gloop. This is invoked when the Redis channel configured for the endpoint receives a message.

Redis-replying service

(1) This line simply prints the channel name and message content to the Martini INFO log.

Groovy script as service

Consider this Groovy script that simply prints the available variables in the context:

    'content'].each {

    println "$it\t : " + this[it]

When the endpoint is triggered - in this case, a Redis message sent to the configured channel - the console will show logs similar to the following:

parameters    : [ <omitted> ]
martiniPackage    : martiniPackage [name=examples]
properties    : [ <omitted> ]
channel    : Channel1
pattern    : null
message    : Hello Martini!"}
$trackerId    : null
content    : Hello Martini!

Groovy method as service

We can configure the endpoint to use Groovy methods as services as well. Consider the following example:

class TestRedis {

    static void helloRedis(def message) {
        "Message received from Redis: ${message}".warn()


Assuming the service TestRedis#helloRedis is configured in the endpoint, we can trigger it by sending a message to a matching channel.