Sample-txc-mq sample

更新时间: 2026-04-01 09:50:17

This sample shows how to send MQ transactional messages as part of a GTS-managed global transaction.

Prerequisites

Before you begin, ensure that you have completed the following:

How it works

Account A transfers funds to account B 10 times. The first five transfers succeed, and the last five fail. After each successful transfer, a notification is sent through MQ. GTS ensures that the total balance of account A and account B remains unchanged and that an MQ notification is sent only when a transfer is successful.

Build and run the sample

  1. Download the txc-yun-sample project and upload it to your ECS instance.
  2. txc_sample1.sql txc_sample2.sqltxc_undo_log.sqlIn each of the two RDS instances, run the , , and scripts from the directory of the sample to create data tables.
  3. Modify the sample configuration.
    1. sample-txc-mq/src/main/resourcestxc-mq-client-context.xmlOpen the file in the directory.
    2. constructor-arg valueReplace the value of with your GTS transaction group ID.
    3. Under the <bean id="txc_mq_producer" class="com.taobao.txc.rm.mq.TxcMQProducerImpl"> element, replace the parameters with your MQ configuration.
    4. Update the values for accessKey and secretKey with your account credentials.
      Note Use the AccessKey ID and AccessKey Secret of your primary account. If you use credentials for a RAM user, you must first authorize that user from your primary account.
  4. sample-txc-mqbuild.shIn the directory, run to build the project.
  5. After the build is complete, navigate to the sample-txc-mq/client/bin directory and run run.sh to start the sample.
    Check the runtime output of the MQ provider.
  6. Upload the sample-mq-consumer project to your ECS instance.
  7. sample-mq-consumer/src/main/java/com/taobao/txc/testsSMSListener.javaIn the directory, open and replace with your MQ configuration details.
  8. sample-mq-consumerbuild.shIn the directory, run to build the project.
  9. After the build is complete, navigate to the sample-mq-consumer/client/bin directory and run run.sh to start the sample.
    The consumer now starts consuming the MQ messages produced by the sample-txc-mq project.
上一篇: sample-txc-simple example 下一篇: sample-txc-edas sample