Sample-txc-mq sample
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:- Activate GTS and create a transaction group.
- Activate MQ. For more information, see Quick Start Overview.
- Prepare two RDS instances and create a database on each instance.
- Prepare an ECS instance to deploy this sample.
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
- Download the txc-yun-sample project and upload it to your ECS instance.
- 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.
- Modify the sample configuration.
- sample-txc-mq/src/main/resourcestxc-mq-client-context.xmlOpen the file in the directory.
- constructor-arg valueReplace the value of with your GTS transaction group ID.
- Under the
<bean id="txc_mq_producer" class="com.taobao.txc.rm.mq.TxcMQProducerImpl">element, replace the parameters with your MQ configuration. - Update the values for
accessKeyandsecretKeywith 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.
- sample-txc-mqbuild.shIn the directory, run to build the project.
- After the build is complete, navigate to the
sample-txc-mq/client/bindirectory and runrun.shto start the sample.Check the runtime output of the MQ provider. - Upload the
sample-mq-consumerproject to your ECS instance. - sample-mq-consumer/src/main/java/com/taobao/txc/testsSMSListener.javaIn the directory, open and replace with your MQ configuration details.
- sample-mq-consumerbuild.shIn the directory, run to build the project.
- After the build is complete, navigate to the
sample-mq-consumer/client/bindirectory and runrun.shto start the sample.The consumer now starts consuming the MQ messages produced by thesample-txc-mqproject.