### Application Startup Commands Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/sentinel-example/README.md Provides instructions for starting the Spring Cloud Alibaba Sentinel example application. It includes commands for compiling the project using Maven and running the packaged JAR file, as well as instructions for direct IDE startup. ```shell # Compile and package mvn clean package # Start after packaging java -jar sentinel-core-example.jar ``` -------------------------------- ### Package and Install Helm Chart Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/integrated-example/docs/zh/kubernetes-deployment-zh.md Package the Helm chart and install the integrated example application. Ensure you are in the 'spring-cloud-alibaba-examples/integrated-example' directory. ```shell helm package helm-chart helm install integrated-example integrated-example-1.0.0.tgz ``` -------------------------------- ### Start Spring Cloud Alibaba Example Services with Docker Compose Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/integrated-example/docs/en/docker-compose-deployment.md This command deploys the micro-services for the Spring Cloud Alibaba integration example using a specific Docker Compose file. The '-d' flag runs the services in the background. ```shell docker-compose -f ./docker-compose/docker-compose-service.yml up -d ``` -------------------------------- ### Startup Nacos Server (Bash) Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/readme.md Commands to download and start the Nacos server in standalone mode. This is a prerequisite for using Spring Cloud Alibaba Sidecar with Nacos for service discovery. ```bash # Download Nacos (example link, use actual download link) # wget # Unzip Nacos unzip nacos-*.zip cd nacos-* # Startup Name Server in standalone mode startup.cmd -m standalone ``` -------------------------------- ### Start Seata-server Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme-zh.md Commands to launch the Seata-server on different operating systems. ```cmd ./seata-server.bat ``` ```shell sh seata-server.sh ``` -------------------------------- ### Start RocketMQ Broker Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md This bash command starts a RocketMQ Broker, which is the core message server. It requires the Name Server's address to register itself and begin handling message production and consumption. ```bash sh bin/mqbroker -n localhost:9876 ``` -------------------------------- ### Start Seata-server Service Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme.md Commands to launch the Seata-server process on different operating systems. ```cmd ./seata-server.bat ``` ```shell sh seata-server.sh ``` -------------------------------- ### Start Spring Cloud Alibaba Environment Components with Docker Compose Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/integrated-example/docs/en/docker-compose-deployment.md This command initiates the core components required for the Spring Cloud Alibaba integration example, such as databases and Nacos, using a Docker Compose configuration file. The '-d' flag ensures the containers run in detached mode. ```shell docker-compose -f ./docker-compose/docker-compose-env.yml up -d ``` -------------------------------- ### Run Packaged Application Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/nacos-example/readme.md Command to run the compiled JAR file of the nacos-discovery-consumer-example project. This starts the application after packaging. ```bash java -jar nacos-discovery-consumer-example.jar ``` -------------------------------- ### Check Transaction Logs Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme-zh.md Example log output showing XID propagation across services. ```bash # 分别查看服务运行日志(示例) Account Service ... xid: 192.168.44.1:8091:4540309594179612673 Order Service Begin ... xid: 192.168.44.1:8091:4540309594179612673 Storage Service Begin ... xid: 192.168.44.1:8091:4540309594179612673 ... Begin new global transaction [192.168.44.1:8091:4540309594179612673] ``` -------------------------------- ### Start RocketMQ Name Server Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md This bash command initiates the RocketMQ Name Server, which is a crucial component for the RocketMQ cluster. The Name Server is responsible for managing broker information and routing messages. ```bash sh bin/mqnamesrv ``` -------------------------------- ### Manage Helm Deployment Lifecycle Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/integrated-example/docs/en/kubernetes-deployment.md Commands to package, install, and uninstall Spring Cloud Alibaba applications using Helm. These commands manage the deployment of the integrated example stack within a Kubernetes cluster. ```shell helm package helm-chart helm install integrated-example integrated-example-1.0.0.tgz helm uninstall integrated-example ``` -------------------------------- ### Start Nacos Server (Windows) Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/nacos-example/readme-zh.md Command to start Nacos Server on Windows operating systems. Navigate to the nacos/bin directory before executing. ```cmd cmd startup.cmd ``` -------------------------------- ### Example Job Execution Log Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/spring-cloud-scheduling-example/README.md This log output indicates that the scheduled jobs 'job1' and 'job2' are executing as expected every minute. ```text 2024-05-17T11:20:59.981+08:00 INFO 66613 --- [spring-cloud-alibaba-schedule-example] [ sca-schedule-4] c.a.c.examples.schedule.job.SimpleJob : time=2024-05-17 11:20:59 do job1... 2024-05-17T11:20:59.985+08:00 INFO 66613 --- [spring-cloud-alibaba-schedule-example] [ sca-schedule-1] c.a.c.examples.schedule.job.SimpleJob : time=2024-05-17 11:20:59 do job2... ``` -------------------------------- ### Create Database Tables for Application Sample (SQL) Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme.md SQL script to create 'storage_tbl', 'order_tbl', and 'account_tbl' tables. These tables are essential for the application's data storage and transactional integrity. ```sql DROP TABLE IF EXISTS `storage_tbl`; CREATE TABLE `storage_tbl` ( `id` int(11) NOT NULL AUTO_INCREMENT, `commodity_code` varchar(255) DEFAULT NULL, `count` int(11) DEFAULT 0, PRIMARY KEY (`id`), UNIQUE KEY (`commodity_code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `order_tbl`; CREATE TABLE `order_tbl` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` varchar(255) DEFAULT NULL, `commodity_code` varchar(255) DEFAULT NULL, `count` int(11) DEFAULT 0, `money` int(11) DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; DROP TABLE IF EXISTS `account_tbl`; CREATE TABLE `account_tbl` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` varchar(255) DEFAULT NULL, `money` int(11) DEFAULT 0, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; ``` -------------------------------- ### Accessing Sample URLs Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme.md These URLs are used to test the business-service's ability to call other services using RestTemplate and FeignClient. The expected outcomes are either a SUCCESS message or a 500 exception. ```shell http://127.0.0.1:18081/seata/feign http://127.0.0.1:18081/seata/rest ``` -------------------------------- ### Application Configuration (YAML) Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/sentinel-example/README.md Basic application configuration for the Spring Cloud Alibaba Sentinel example. It sets the server port, application name, and Sentinel dashboard address. This configuration is essential for the application to run and connect to the Sentinel dashboard. ```yaml server: port: 18083 spring: application: name: sentinel-core-example cloud: sentinel: transport: dashboard: localhost:8080 ``` -------------------------------- ### ReadableDataSource Load Log Output Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/sentinel-example/README-zh.md Example of log messages generated by the Sentinel Starter when rule data is successfully loaded from configured sources. ```text [Sentinel Starter] DataSource ds1-sentinel-file-datasource load 3 DegradeRule [Sentinel Starter] DataSource ds2-sentinel-nacos-datasource load 2 FlowRule ``` -------------------------------- ### RocketMQ Binder Metrics Response Example Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md This provides an example of the JSON response you can expect when accessing the RocketMQ Binder endpoint, detailing various runtime and metrics information. ```APIDOC ## Metrics Response Example ### Description This is an example of the JSON payload returned by the RocketMQ Binder endpoint, containing runtime information and various message sending/receiving metrics. ### Response Example (Success Response - 200) ```json { "runtime": { "lastSend.timestamp": 1542786623915 }, "metrics": { "scs-rocketmq.consumer.test-topic.totalConsumed": { "count": 11 }, "scs-rocketmq.consumer.test-topic.totalConsumedFailures": { "count": 0 }, "scs-rocketmq.producer.test-topic.totalSentFailures": { "count": 0 }, "scs-rocketmq.consumer.test-topic.consumedPerSecond": { "count": 11, "fifteenMinuteRate": 0.012163847780107841, "fiveMinuteRate": 0.03614605351360527, "meanRate": 0.3493213353657594, "oneMinuteRate": 0.17099243039490175 }, "scs-rocketmq.producer.test-topic.totalSent": { "count": 5 }, "scs-rocketmq.producer.test-topic.sentPerSecond": { "count": 5, "fifteenMinuteRate": 0.005540151995103271, "fiveMinuteRate": 0.01652854617838251, "meanRate": 0.10697493212602836, "oneMinuteRate": 0.07995558537067671 }, "scs-rocketmq.producer.test-topic.sentFailuresPerSecond": { "count": 0, "fifteenMinuteRate": 0.0, "fiveMinuteRate": 0.0, "meanRate": 0.0, "oneMinuteRate": 0.0 }, "scs-rocketmq.consumer.test-topic.consumedFailuresPerSecond": { "count": 0, "fifteenMinuteRate": 0.0, "fiveMinuteRate": 0.0, "meanRate": 0.0, "oneMinuteRate": 0.0 } } } ``` ``` -------------------------------- ### Initialize Seata Database Schema Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme.md SQL scripts to create the undo_log table for AT mode and the required global/branch transaction tables for the Seata server. ```sql CREATE TABLE `undo_log` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `branch_id` bigint(20) NOT NULL, `xid` varchar(100) NOT NULL, `context` varchar(128) NOT NULL, `rollback_info` longblob NOT NULL, `log_status` int(11) NOT NULL, `log_created` datetime NOT NULL, `log_modified` datetime NOT NULL, `ext` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `global_table` ( `xid` VARCHAR(128) NOT NULL, `transaction_id` BIGINT, `status` TINYINT NOT NULL, `application_id` VARCHAR(32), `transaction_service_group` VARCHAR(32), `transaction_name` VARCHAR(128), `timeout` INT, `begin_time` BIGINT, `application_data` VARCHAR(2000), `gmt_create` DATETIME, `gmt_modified` DATETIME, PRIMARY KEY (`xid`), KEY `idx_status_gmt_modified` (`status` , `gmt_modified`), KEY `idx_transaction_id` (`transaction_id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; CREATE TABLE IF NOT EXISTS `branch_table` ( `branch_id` BIGINT NOT NULL, `xid` VARCHAR(128) NOT NULL, `transaction_id` BIGINT, `resource_group_id` VARCHAR(32), `resource_id` VARCHAR(256), `branch_type` VARCHAR(8), `status` TINYINT, `client_id` VARCHAR(64), `application_data` VARCHAR(2000), `gmt_create` DATETIME(6), `gmt_modified` DATETIME(6), PRIMARY KEY (`branch_id`), KEY `idx_xid` (`xid`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; CREATE TABLE IF NOT EXISTS `lock_table` ( `row_key` VARCHAR(128) NOT NULL, `xid` VARCHAR(128), `transaction_id` BIGINT, `branch_id` BIGINT NOT NULL, `resource_id` VARCHAR(256), `table_name` VARCHAR(32), `pk` VARCHAR(36), `status` TINYINT NOT NULL DEFAULT '0', `gmt_create` DATETIME, `gmt_modified` DATETIME, PRIMARY KEY (`row_key`), KEY `idx_status` (`status`), KEY `idx_branch_id` (`branch_id`), KEY `idx_xid_and_branch_id` (`xid` , `branch_id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; CREATE TABLE IF NOT EXISTS `distributed_lock` ( `lock_key` CHAR(20) NOT NULL, `lock_value` VARCHAR(20) NOT NULL, `expire` BIGINT, primary key (`lock_key`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; ``` -------------------------------- ### Start Nacos Server Standalone (Linux/Unix/Mac) Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/nacos-example/readme-zh.md Command to start Nacos Server in standalone mode on Linux, Unix, or Mac operating systems. Ensure you are in the nacos/bin directory. ```bash sh startup.sh -m standalone ``` -------------------------------- ### Create RocketMQ Topic using mqadmin Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md This bash command uses the RocketMQ admin tool to create a new topic named 'test-topic'. This topic will be used for publishing and subscribing to messages within the RocketMQ cluster, connected to the specified name server and cluster. ```bash sh bin/mqadmin updateTopic -n localhost:9876 -c DefaultCluster -t test-topic ``` -------------------------------- ### Configure Seata Database Connection in YAML Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme.md Template for defining database connection parameters in the application.yml file for microservices using Seata. ```yaml base: config: mdb: hostname: your mysql server ip address dbname: your database name for test port: your mysql server listening port username: your mysql server username password: your mysql server password ``` -------------------------------- ### Implement RocketMQ Broadcasting Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md Provides the configuration and implementation for a broadcast messaging pattern, including topic creation via CLI, producer configuration using StreamBridge, and consumer configuration with BROADCASTING message model. ```shell sh bin/mqadmin updateTopic -n localhost:9876 -c DefaultCluster -t broadcast ``` ```yaml spring: cloud: stream: rocketmq: binder: name-server: localhost:9876 bindings: producer-out-0: producer: group: output_1 bindings: producer-out-0: destination: broadcast ``` ```java @Bean public ApplicationRunner producer() { return args -> { for (int i = 0; i < 100; i++) { String key = "KEY" + i; Map headers = new HashMap<>(); headers.put(MessageConst.PROPERTY_KEYS, key); Message msg = new GenericMessage(new SimpleMsg("Hello RocketMQ " + i), headers); streamBridge.send("producer-out-0", msg); } }; } ``` -------------------------------- ### Verifying Xid Information in Service Logs Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme.md This command shows how to view service operation logs to verify that Seata's Xid is passed and restored correctly across different services. The Xid should be consistent for all services within the same invocation. ```bash # View service operation logs separately (example) Account Service ... xid: 192.168.44.1:8091:4540309594179612673 Order Service Begin ... xid: 192.168.44.1:8091:4540309594179612673 Storage Service Begin ... xid: 192.168.44.1:8091:4540309594179612673 ... Begin new global transaction [192.168.44.1:8091:4540309594179612673] ``` -------------------------------- ### Configure Flow Rules Programmatically Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/sentinel-example/README.md Define and load flow control rules using the FlowRuleManager to set QPS limits for specific resources within the application. ```java List rules = new ArrayList(); FlowRule rule = new FlowRule(); rule.setResource(str); // set limit qps to 10 rule.setCount(10); rule.setGrade(RuleConstant.FLOW_GRADE_QPS); rule.setLimitApp("default"); rules.add(rule); FlowRuleManager.loadRules(rules); ``` -------------------------------- ### Configure Nacos Server Address and Import Configuration Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/nacos-example/readme.md Configure the Nacos server address, credentials, and import a specific Nacos configuration file in `application.yaml`. This setup allows the application to fetch configurations from Nacos. ```yaml spring: cloud: nacos: serverAddr: 127.0.0.1:8848 username: 'nacos' password: 'nacos' config: import: - nacos:nacos-config-example.properties?refreshEnabled=true&group=DEFAULT_GROUP ``` -------------------------------- ### Create RocketMQ Orderly Topic Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md Uses the RocketMQ administrative tool to create a new topic configured for ordered message processing within the default cluster. ```bash sh bin/mqadmin updateTopic -n localhost:9876 -c DefaultCluster -t orderly ``` -------------------------------- ### Configure Spring Cloud Alibaba Sidecar and Nacos (YAML) Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/readme.md Configures the Sidecar and Nacos discovery settings in application.yml. This includes setting the server port, Nacos credentials and server address, gateway discovery locator, application name, and the IP/port/health check URL for the heterogeneous service. ```yaml server: port: 8070 spring: cloud: nacos: username: nacos password: nacos discovery: server-addr: 127.0.0.1:8848 group: test gateway: discovery: locator: enabled: true application: name: node-service sidecar: # heterogeneous service‘s ip ip: 127.0.0.1 # heterogeneous service's port port: 8060 # heterogeneous service's health check URL health-check-url: http://localhost:8060/health.json ``` -------------------------------- ### Produce Messages with Spring Cloud Alibaba RocketMQ Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md Demonstrates two methods for producing messages: using the Spring Cloud Stream MessageChannel abstraction for integrated messaging and the native RocketMQ DefaultMQProducer API for direct control. ```java public class ProducerRunner implements CommandLineRunner { @Autowired private MessageChannel output; @Override public void run(String... args) throws Exception { Map headers = new HashMap<>(); headers.put(MessageConst.PROPERTY_TAGS, "tagStr"); Message message = MessageBuilder.createMessage(msg, new MessageHeaders(headers)); output.send(message); } } ``` ```java public class RocketMQProducer { DefaultMQProducer producer = new DefaultMQProducer("producer_group"); producer.setNamesrvAddr("127.0.0.1:9876"); producer.start(); Message msg = new Message("test-topic", "tagStr", "message from rocketmq producer".getBytes()); producer.send(msg); } ``` -------------------------------- ### Verifying Database Consistency with SQL Queries Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme.md These SQL queries are used to check the consistency of data in the account, storage, and order tables after a distributed transaction. This helps verify that operations like inventory deduction and balance updates are correctly reflected or rolled back. ```sql SELECT * FROM account_tbl; SELECT * FROM storage_tbl; SELECT * FROM order_tbl; ``` -------------------------------- ### Initialize Nacos Configurations using a Shell Script Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/integrated-example/docs/en/docker-compose-deployment.md This script automates the import of all micro-service configurations into Nacos. It's designed to be executed after the Nacos server has been started via Docker Compose, ensuring that services can retrieve their configurations. ```shell config-init/scripts/nacos-config-quick.sh ``` -------------------------------- ### Configure Sentinel ReadableDataSources in Spring Properties Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/sentinel-example/README.md Demonstrates how to define File and Nacos data sources for Sentinel rules. These configurations allow for dynamic rule loading by specifying the data type and source-specific parameters in application properties. ```properties spring.cloud.sentinel.datasource.ds1.file.file=classpath: degraderule.json spring.cloud.sentinel.datasource.ds1.file.data-type=json spring.cloud.sentinel.datasource.ds2.nacos.server-addr=127.0.0.1:8848 spring.cloud.sentinel.datasource.ds2.nacos.dataId=sentinel spring.cloud.sentinel.datasource.ds2.nacos.groupId=DEFAULT_GROUP spring.cloud.sentinel.datasource.ds2.nacos.data-type=json ``` -------------------------------- ### Declare Spring Cloud Alibaba Sidecar Dependencies (Maven) Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/readme.md Adds the necessary Maven dependencies for Spring Cloud Alibaba Sidecar, Nacos discovery, and WebFlux gateway to the project's pom.xml. These dependencies enable the Sidecar functionality and integration with Nacos for service registration and discovery. ```xml org.springframework.cloud spring-cloud-starter-gateway-server-webflux com.alibaba.cloud spring-cloud-starter-alibaba-sidecar com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery ``` -------------------------------- ### Create RocketMQ Topic (Shell Script) Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md A shell command to create a topic named 'delay' in RocketMQ. This command uses the `mqadmin` tool to update the topic configuration on the specified name server. It's a prerequisite for using scheduled or delayed messages. ```sh sh bin/mqadmin updateTopic -n localhost:9876 -c DefaultCluster -t delay ``` -------------------------------- ### Initialize Seata Server Database Tables Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme-zh.md Set up the global_table, branch_table, lock_table, and distributed_lock tables for Seata server storage mode. ```sql -- -------------------------------- The script used when storeMode is 'db' -------------------------------- -- the table to store GlobalSession data CREATE TABLE IF NOT EXISTS `global_table` ( `xid` VARCHAR(128) NOT NULL, `transaction_id` BIGINT, `status` TINYINT NOT NULL, `application_id` VARCHAR(32), `transaction_service_group` VARCHAR(32), `transaction_name` VARCHAR(128), `timeout` INT, `begin_time` BIGINT, `application_data` VARCHAR(2000), `gmt_create` DATETIME, `gmt_modified` DATETIME, PRIMARY KEY (`xid`), KEY `idx_status_gmt_modified` (`status` , `gmt_modified`), KEY `idx_transaction_id` (`transaction_id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; -- the table to store BranchSession data CREATE TABLE IF NOT EXISTS `branch_table` ( `branch_id` BIGINT NOT NULL, `xid` VARCHAR(128) NOT NULL, `transaction_id` BIGINT, `resource_group_id` VARCHAR(32), `resource_id` VARCHAR(256), `branch_type` VARCHAR(8), `status` TINYINT, `client_id` VARCHAR(64), `application_data` VARCHAR(2000), `gmt_create` DATETIME(6), `gmt_modified` DATETIME(6), PRIMARY KEY (`branch_id`), KEY `idx_xid` (`xid`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; -- the table to store lock data CREATE TABLE IF NOT EXISTS `lock_table` ( `row_key` VARCHAR(128) NOT NULL, `xid` VARCHAR(128), `transaction_id` BIGINT, `branch_id` BIGINT NOT NULL, `resource_id` VARCHAR(256), `table_name` VARCHAR(32), `pk` VARCHAR(36), `status` TINYINT NOT NULL DEFAULT '0' COMMENT '0:locked ,1:rollbacking', `gmt_create` DATETIME, `gmt_modified` DATETIME, PRIMARY KEY (`row_key`), KEY `idx_status` (`status`), KEY `idx_branch_id` (`branch_id`), KEY `idx_xid_and_branch_id` (`xid` , `branch_id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; CREATE TABLE IF NOT EXISTS `distributed_lock` ( `lock_key` CHAR(20) NOT NULL, `lock_value` VARCHAR(20) NOT NULL, `expire` BIGINT, primary key (`lock_key`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('AsyncCommitting', ' ', 0); INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryCommitting', ' ', 0); INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('RetryRollbacking', ' ', 0); INSERT INTO `distributed_lock` (lock_key, lock_value, expire) VALUES ('TxTimeoutCheck', ' ', 0); ``` -------------------------------- ### Request Nacos API with Access Token Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/nacos-example/readme-zh.md Example of using curl to request a Nacos API endpoint (getting configs) with a previously obtained access token. Replace the token with a valid one. ```bash curl -X GET '127.0.0.1:8848/nacos/v1/cs/configs?accessToken=eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJuYWNvcyIsImV4cCI6MTYwNTYyMzkyM30.O-s2yWfDSUZ7Svd3Vs7jy9tsfDNHs1SuebJB4KlNY8Q&dataId=nacos.example.1&group=nacos_group' ``` -------------------------------- ### Configure Maven Settings for GitHub Packages Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/README.md Add server credentials to your settings.xml file for accessing GitHub Packages. Replace 'Your GitHub Username' and 'Your GitHub Token' with your actual credentials. ```xml github Your GitHub Username Your GitHub Token (requires read:packages permission) ``` -------------------------------- ### Enable Spring Cloud Stream Bindings for RocketMQ Application Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md This Java code snippet illustrates the main application class setup for a Spring Cloud application using Spring Cloud Stream with RocketMQ. It enables the Source and Sink interfaces, which are fundamental for publishing and subscribing to messages. ```java @SpringBootApplication @EnableBinding({ Source.class, Sink.class }) public class RocketMQApplication { public static void main(String[] args) { SpringApplication.run(RocketMQApplication.class, args); } } ``` -------------------------------- ### Build Spring Cloud Alibaba Project with Maven Wrapper Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/README.md Use the Maven wrapper to build the project. Ensure you are on the correct branch corresponding to your desired Spring Cloud and Spring Boot versions. ```bash ./mvnw install ``` -------------------------------- ### Observe Docker Compose Container Startup Process Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/integrated-example/docs/en/docker-compose-deployment.md This command allows you to monitor the real-time startup logs of containers managed by Docker Compose. It's useful for debugging and understanding the deployment process. ```shell docker-compose -f docker-compose-*.yml up ``` -------------------------------- ### Customize Sentinel Current Limit Exception Handling with @SentinelResource Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/sentinel-example/README.md This example demonstrates customizing Sentinel's current limit and fallback exception handling using the @SentinelResource annotation. It shows how to specify custom `blockHandler` and `fallback` methods, including their signatures and locations, for handling different exception types. The `blockHandler` is used for `BlockException` and the `fallback` is for fuse degradation exceptions. ```java public class TestService { // blockHandler is a static method in the ExceptionUtil class, which must meet the corresponding type restrictions. @SentinelResource(value = "test", blockHandler = "handleException", blockHandlerClass = {ExceptionUtil.class}) public void test() { System.out.println("Test"); } // blockHandler is the exceptionHandler method in the current class, which must meet the corresponding type restrictions. @SentinelResource(value = "hello", blockHandler = "exceptionHandler") public String hello(long s) { return String.format("Hello at %d", s); } public String exceptionHandler(long s, BlockException ex) { // Do some log here. ex.printStackTrace(); return "Oops, error occurred at " + s; } } public final class ExceptionUtil { public static void handleException(BlockException ex) { System.out.println("Oops: " + ex.getClass().getCanonicalName()); } } ``` -------------------------------- ### Compile and Package Project Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/nacos-example/readme.md Command to compile and package the nacos-discovery-consumer-example project using Maven. This prepares the application for execution. ```bash mvn clean package ``` -------------------------------- ### Heterogeneous Service Health Check Response (JSON) Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/readme.md Example JSON response for the health check URL configured for the heterogeneous service. This format is expected by the Sidecar for health monitoring of the non-Java microservice. ```json { "status": "DOWN" } ``` -------------------------------- ### Add Eureka and ANS Starter Dependencies Source: https://github.com/alibaba/spring-cloud-alibaba/wiki/Eureka-向-ANS-迁移 During the migration phase, include both Eureka client and ANS starter dependencies in your project. Ensure you are using version 0.2.2.BUILD-SNAPSHOT or higher for the ANS starter. ```xml org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.cloud spring-cloud-starter-alicloud-ans 0.2.2.BUILD-SNAPSHOT ``` -------------------------------- ### Implement RocketMQ SQL-based Message Filtering Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md Shows how to configure SQL-based message filtering in RocketMQ using Spring Cloud Stream. The example includes the necessary shell command to create a topic and the Java logic to attach filterable headers to messages. ```bash sh bin/mqadmin updateTopic -n localhost:9876 -c DefaultCluster -t sql ``` ```yaml spring: cloud: stream: rocketmq: bindings: consumer-in-0: consumer: subscription: sql:(color in ('red1', 'red2', 'red4') and price>3) ``` ```java @Bean public ApplicationRunner producer() { return args -> { for (int i = 0; i < 100; i++) { Map headers = new HashMap<>(); headers.put("color", color[i % color.length]); headers.put("price", price[i % price.length]); Message msg = new GenericMessage(new SimpleMsg("Hello RocketMQ " + i), headers); streamBridge.send("producer-out-0", msg); } }; } ``` -------------------------------- ### Configure SchedulerX for Cloud Product Integration Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/spring-cloud-scheduling-example/README.md Configure the scheduling to use Alibaba's SchedulerX service. You need to obtain specific credentials from the Alibaba Cloud console. ```yaml spring: cloud: scheduling: # Distributed mode: shedlock, schedulerx # Set config value: schedulerx distributed-mode: schedulerx schedulerx: # This configuration is required, Please get it from aliyun schedulerx console endpoint: acm.aliyun.com namespace: aad167f6-xxxx-xxxx-xxxx-xxxxxxxxx groupId: xxxxx appKey: PZm1XXXXXXXXXXXX # Optional config, if you need to sync task to schedulerx # task-sync: true # region-id: public # aliyun-access-key: XXXXXXXXXXXX # aliyun-secret-key: XXXXXXXXXXXX # task-model-default: standalone ``` -------------------------------- ### Configure Maven Repositories for Snapshots Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/README.md Add the GitHub repository to your Maven configuration to access snapshot versions. Consider using Alibaba Cloud Effect Artifact Repository as a proxy if you face access issues. ```xml github https://maven.pkg.github.com/alibaba/spring-cloud-alibaba false true ``` -------------------------------- ### Uninstall Helm Release Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/integrated-example/docs/zh/kubernetes-deployment-zh.md Command to stop and remove the deployed integrated example application from Kubernetes. ```shell helm uninstall integrated-example ``` -------------------------------- ### Set Nacos Server Identity Key Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/nacos-example/readme-zh.md Configure the identity key for Nacos server authentication. This is part of the security setup for the server. ```properties nacos.core.auth.server.identity.key=test nacos.core.auth.server.identity.value=test ``` -------------------------------- ### Metrics Dependency Warning Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md This section explains the requirement for the `metrics-core` dependency to view metrics data and the warning message displayed if it's missing. ```APIDOC ## Metrics Dependency ### Description To view detailed metrics data, you must include the `metrics-core` dependency in your project. If this dependency is not added, the endpoint will display a warning message. ### Dependency Add the following dependency to your `pom.xml`: ```xml io.dropwizard.metrics metrics-core ... ``` Refer to: [metrics-core dependency](https://mvnrepository.com/artifact/io.dropwizard.metrics/metrics-core) ### Warning Response Example (if metrics-core is missing) ```json { "warning": "please add metrics-core dependency, we use it for metrics" } ``` ``` -------------------------------- ### Configure Seata-server Storage and Server Settings Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme-zh.md Optional configuration for database storage mode and server-side operational parameters. ```yml store: # 支持:file、db、redis、raft mode: db # 使用数据库模式 session: mode: file lock: mode: file db: datasource: druid db-type: mysql driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/seata?rewriteBatchedStatements=true # MySQL 数据库连接 user: root # MySQL 用户名 password: rootpass # MySQL 密码 min-conn: 10 max-conn: 100 global-table: global_table branch-table: branch_table lock-table: lock_table distributed-lock-table: distributed_lock vgroup-table: vgroup_table query-limit: 1000 max-wait: 5000 server: service-port: 8091 # 配置服务端口 max-commit-retry-timeout: -1 max-rollback-retry-timeout: -1 rollback-failed-unlock-enable: false enable-check-auth: true enable-parallel-request-handle: true enable-parallel-handle-branch: false retry-dead-threshold: 70000 xaer-nota-retry-timeout: 60000 enableParallelRequestHandle: true applicationDataLimitCheck: true applicationDataLimit: 64000 recovery: committing-retry-period: 1000 async-committing-retry-period: 1000 rollbacking-retry-period: 1000 end-status-retry-period: 1000 timeout-retry-period: 1000 undo: log-save-days: 7 log-delete-period: 86400000 session: branch-async-queue-size: 5000 # 异步分支队列大小 enable-branch-async-remove: false # 启用分支异步移除 ratelimit: enable: false bucketTokenNumPerSecond: 999999 bucketTokenMaxNum: 999999 bucketTokenInitialNum: 999999 metrics: enabled: false registry-type: compact exporter-list: prometheus exporter-prometheus-port: 9898 transport: rpc-tc-request-timeout: 15000 enable-tc-server-batch-send-response: false min-http-pool-size: 10 max-http-pool-size: 100 max-http-task-queue-size: 1000 http-pool-keep-alive-time: 500 shutdown: wait: 3 thread-factory: boss-thread-prefix: NettyBoss worker-thread-prefix: NettyServerNIOWorker boss-thread-size: 1 ``` -------------------------------- ### Consume Messages with @StreamListener Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/rocketmq-example/readme.md Shows how to use the @StreamListener annotation to handle incoming messages from specific input channels within a Spring service. ```java @Service public class ReceiveService { @StreamListener("input1") public void receiveInput1(String receiveMsg) { System.out.println("input1 receive: " + receiveMsg); } @StreamListener("input2") public void receiveInput2(String receiveMsg) { System.out.println("input2 receive: " + receiveMsg); } } ``` -------------------------------- ### Migration Status Endpoint (Spring Boot 2.x) Source: https://github.com/alibaba/spring-cloud-alibaba/wiki/Eureka-向-ANS-迁移 Access the 'migrate' endpoint to view the current migration status. This example shows the output when migrating a service that was previously registered with Eureka. ```json Endpoint Url: http://localhost:port/actuator/migrate { "sc-migrate-eureka-consumer": { "30.5.125.22:40051": { "server": { // **** 省略 "instanceInfo": { "instanceId": "30.5.125.22:sc-migrate-eureka-consumer:40051", "app": "SC-MIGRATE-EUREKA-CONSUMER", "appGroupName": null, "ipAddr": "30.5.125.22", "sid": "na", "homePageUrl": "http://30.5.125.22:40051/", "statusPageUrl": "http://30.5.125.22:40051/actuator/info", "healthCheckUrl": "http://30.5.125.22:40051/actuator/health", "secureHealthCheckUrl": null, "vipAddress": "sc-migrate-eureka-consumer", "secureVipAddress": "sc-migrate-eureka-consumer", "countryId": 1, "dataCenterInfo": { "@class": "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo", "name": "MyOwn" }, // **** }, "callCount": 8 //服务调用时选择该实例被调用的次数 }, "30.5.125.22:40052": { "server": { // **** 省略 "metaInfo": { "instanceId": "30.5.125.22:sc-migrate-eureka-consumer:40052", "appName": "sc-migrate-eureka-consumer", "serverGroup": null, "serviceIdForDiscovery": "sc-migrate-eureka-consumer" }, "metadata": { "source": "ANS" // 如果该实例是来自于 ANS,将会有此标识 }, // **** 省略 }, "callCount": 9 //服务调用时选择该实例被调用的次数 } } } ``` -------------------------------- ### Configure Database Connection Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/seata-example/readme-zh.md Update the application.yml files in account-server, order-service, and storage-service with local database credentials. ```yaml base: config: mdb: hostname: your mysql server ip address dbname: your database name for test port: your mysql server listening port username: your mysql server username password: your mysql server password ``` -------------------------------- ### Simulate Order Creation Request Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/integrated-example/docs/zh/kubernetes-deployment-zh.md Access the order service frontend to simulate a client request to the gateway for creating an order. This involves specifying userId, productId, and quantity. ```http http://integrated-frontend:30080/order ``` -------------------------------- ### Configure Sentinel Dependency in Maven Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/sentinel-example/README.md Add the spring-cloud-starter-alibaba-sentinel dependency to your pom.xml to enable Sentinel traffic management features in your Spring Cloud project. ```xml com.alibaba.cloud spring-cloud-starter-alibaba-sentinel ``` -------------------------------- ### Add Nacos Discovery Starter Dependency Source: https://github.com/alibaba/spring-cloud-alibaba/blob/2025.1.x/spring-cloud-alibaba-examples/nacos-example/readme-zh.md Include this dependency in your pom.xml to enable Nacos service discovery. ```xml com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery ```