Subscribing to scheduled messages

The message service can generate and send regularly scheduled messages to message queues. You can subscribe to scheduled messages by installing a listener on a queue and subscribing to a topic that defines the times you want to be notified. In this example, we add a listener to “MyQueue” and subscribe to the topic “second:30”, which causes the message service to send a message to MyQueue at 30 seconds past each minute:

cms.addListener(“MyQueue”, “MyPackage/MyComp”);
cms.addSelector(“MyQueue”, “topic = ‘<second:30>’”);

To request a message be sent to MyQueue at 15 and 45 minutes past each hour, use this syntax:

cms.addSelector("MyQueue", "topic = '<minute:15>'");
cms.addSelector("MyQueue", "topic = '<minute:45>'");

For information on how to add selectors using EAServer Manager, see Chapter 8, “Setting up the Message Service,” in the EAServer System Administration Guide.

Scheduled messages are delivered to queues with the appropriate selectors within milliseconds of the specified time. The time at which a component receives a message from the queue, however, depends on the number of unprocessed messages in the queue.

Scheduling variables

Scheduled message topic names can be either ‘<minute:NN>’ or ‘<second:NN>’. Additional constraints must include a variable name and value. You can use these variables to define the message topic subscriptions:

Variable

Definition

MINUTE

Number of minutes past the hour

SECOND

Number of seconds past the minute

HOUR_OF_DAY

To specify 5 PM, “HOUR_OF_DAY = 17”

HOUR

Twice a day, at 6 AM and 6 PM, “HOUR = 6”

YEAR

Four-digit year, for example, 2000

MONTH

The name of the month, for example, January, February, and so forth

DATE

Date of the month, 1-31

DAY_OF_MONTH

Same as DATE

DAY_OF_WEEK

The name of the day of the week, for example, Monday, Tuesday, and so forth.

DAY_OF_WEEK_IN_MONTH

To specify the first Sunday in October, MONTH = October and DAY_OF_WEEK = Sunday and DAY_OF_WEEK_IN_MONTH = 1

DAY_OF_YEAR

To specify February 1, “DAY_OF_YEAR = 32”

WEEK_OF_MONTH

The week number within the current month

WEEK_OF_YEAR

The week number within the current year

The variable names are not case sensitive; minute and MINUTE are equivalent. You can find documentation for the variables, whose names correspond to the constants in the Java class java.util.Calendar, in the Java API Specification.

Scheduled messages are not saved to persistent storage and they are not replicated.

A scheduled message includes two properties that indicate the message creation time, which can be accessed by the component:

Property name

Datatype

Format

@t

double

Number of milliseconds since 1 January 1970

ts

string

YYYY-MM-DD HH:MM:SS

You can find the message structure definition in $JAGUAR/html/ir/CtsComponents.html.