RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • StreamSQL
  • AI Agent Framework
  • GFlow Approval Workflow (opens new window)
  • TPCLAW Agent Platform (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • StreamSQL
  • AI Agent Framework
  • GFlow Approval Workflow (opens new window)
  • TPCLAW Agent Platform (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

  • Extension Components

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

  • Agent Framework

  • RuleGo-Server

  • FAQ

  • Endpoint Module

    • Endpoint Overview
    • Quick Start
    • Router
    • DSL
    • API
    • Options
    • Endpoints

      • Rest Endpoint
      • Websocket Endpoint
      • MQTT Endpoint
      • Schedule Endpoint
        • Type
        • Startup configuration
        • Configure cron
        • cron format
        • Example
        • Multi-replica deployment
      • Net Endpoint
      • Kafka Endpoint
      • Nats Endpoint
      • Redis Sub Endpoint
      • Redis Stream Endpoint
      • Rabbitmq Endpoint
      • MYSQL CDC Endpoint
      • OPC_UA Endpoint
      • gRPC Stream Endpoint
      • Beanstalkd Endpoint
      • Wukongim Endpoint
      • Extend Endpoint
      • NSQ Endpoint
      • Pulsar Endpoint
      • net client endpint
      • Websocket Client Endpoint
  • Support

  • StreamSQL

目录

Schedule Endpoint

Schedule Endpoint is used to create and start scheduled tasks. Use cron expressions to define the task trigger time.

# Type

endpoint/schedule

# Startup configuration

None

# Configure cron

router.From configures the cron expression. For example:

  //Execute every 1 second
  router1 := endpoint.NewRouter().From("*/1 * * * * *").Process(func(router *endpoint.Router, exchange *endpoint.Exchange) bool {
      exchange.In.GetMsg().Type = "TEST_MSG_TYPE1"
      fmt.Println("router1 执行...", time.Now().UnixMilli())
      //Business logic, such as reading files, regularly pulling some data to the rule chain for processing

      return true
  }).
//Specify which rule chain ID to process
To("chain:default").End()
1
2
3
4
5
6
7
8
9
10

Other parameters, refer to route Router definition.

# cron format

cron expression represents a set of times, using 6 fields separated by spaces. For example: * * * * * * The fields from left to right represent:

Field Required Allowed values Allowed special characters
Seconds Yes 0-59 * / , -
Minutes Yes 0-59 * / , -
Hours Yes 0-23 * / , -
Day of month Yes 1-31 * / , - ?
Month Yes 1-12 or JAN-DEC * / , -
Day of week Yes 0-6 or SUN-SAT * / , - ?

Note: The values of the Month and Day of week fields are not case sensitive. "SUN", "Sun" and "sun" are all allowed.

You can also use a few predefined variables to replace the cron expression.

Variable Description Equivalent to
@yearly (or @annually) Run once at 0 o'clock on January 1 every year 0 0 0 1 1 *
@monthly Run once at 0 o'clock on the 1st of every month 0 0 0 1 * *
@weekly Run once at 0 o'clock every Sunday 0 0 0 * * 0
@daily (or @midnight) Run once at 0 o'clock every day 0 0 0 * * *
@hourly Run once every hour on the hour 0 0 * * * *

# Example

scheduleEndpoint := endpoint.New(schedule.Type, config, nil)

//Execute every 1 second
router1 := endpoint.NewRouter().From("*/1 * * * * *").Process(func(router *endpoint.Router, exchange *endpoint.Exchange) bool {
  exchange.In.GetMsg().Type = "TEST_MSG_TYPE1"
  fmt.Println("router1 执行...", time.Now().UnixMilli())
  //Business logic, such as reading files, regularly pulling some data to the rule chain for processing
  return true
}).
//Specify which rule chain ID to process
To("chain:default").End()
//Add task route
routeId1, err := scheduleEndpoint.AddRouter(router1)
//Start task
err = scheduleEndpoint.Start()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

The following are example codes using endpoint:

  • RestEndpoint (opens new window)
  • WebsocketEndpoint (opens new window)
  • MqttEndpoint (opens new window)
  • ScheduleEndpoint (opens new window)
  • NetEndpoint (opens new window)
  • KafkaEndpoint (opens new window) (Extended component library)

# Multi-replica deployment

The cron runs inside each process, so every replica fires the same task in a multi-replica deployment. After injecting a distributed lock into the rule chain config (types.WithLocker), each scheduled slot is deduplicated across replicas and the cluster executes each planned time exactly once, without any DSL change. Clocks must be NTP-synchronized.

See Distributed Locker.

Edit this page on GitHub (opens new window)
Last Updated: 2026/09/06, 12:36:03
MQTT Endpoint
Net Endpoint

← MQTT Endpoint Net Endpoint→

Theme by Vdoing | Copyright © 2023-2026 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式