Distributed Transaction Nine _ final conformance code based on reliable messages

Source: Internet
Author: User
Tags datetime log log message queue
Distributed Transaction Nine _ final conformance code based on reliable messages More Dry goodsDistributed transactions two distributed transaction processing three distributed transactions four _ final consistency based on reliable message distributed transaction Five _ based on reliable message final consistency _ exception flow Distributed transaction Six _ regular MQ queue Distributed transaction Seven _ idempotent design Distributed Transaction Eight _ reliable message final consistency scheme Distributed Transaction Nine _ the final conformance code based on reliable message distributed transaction 10_ maximum effort to inform the situation flexible transaction solution: TCC (two stage type, compensated) Alipay Distributed Transaction Services DTS one Distributed Transaction Service DTS two Distributed Transaction Services DTS three Alipay Distributed Transaction Services DTS Four


first, the message service subsystem 1. Table Structure

DROP TABLE IF EXISTS ' rp_transaction_message '; CREATE TABLE ' rp_transaction_message ' (' id ' varchar () not NULL DEFAULT ' COMMENT ' primary key ID ', ' version ' int (one) ' Not NUL L default ' 0 ' COMMENT ' version number ', ' editor ' varchar (+) default null COMMENT ' modifier ', ' creater ' varchar (+) default NULL COM ment ' creator ', ' Edit_time ' datetime DEFAULT NULL COMMENT ' Last modified time ', ' create_time ' datetime NOT NULL default ' 0000-00-00 00 : 00:00 ' COMMENT ' creation time ', ' message_id ' varchar (NOT null DEFAULT ' COMMENT ' message id ', ' message_body ' longtext not NULL COMMENT ' message content ', ' message_data_type ' varchar ($) DEFAULT null COMMENT ' message data type ', ' consumer_queue ' varchar (+) not NULL Default ' COMMENT ' consumption queue ', ' message_send_times ' smallint (6) Not NULL default ' 0 ' COMMENT ' message re-sent ', ' Areadly_dead ' Varc Har () NOT null default ' COMMENT ' is dead ', ' status ' varchar (NOT null default ' COMMENT ' state ', ' remark ' varchar (20 0) Default null COMMENT ' remarks ', ' field1 ' varchar ($) default null COMMENT ' Extended field 1 ', ' Field2 ' VarcHar ($) default null COMMENT ' Extended field 2 ', ' field3 ' varchar ($) default null COMMENT ' Extended field 3 ', PRIMARY key (' ID '), key ' Ak_key_2 ' (' message_id ')) Engine=innodb DEFAULT Charset=utf8;
2, Rptransactionmessageservice.java
Public interface Rptransactionmessageservice {/** * pre-store messages.
	
	
	*/public int savemessagewaitingconfirm (Rptransactionmessage rptransactionmessage) throws messagebizexception;
	 /** * Confirm and send a message.

	
	*/public void Confirmandsendmessage (String messageId) throws messagebizexception;
	 /** * Store and send messages.

	
	*/public int saveandsendmessage (Rptransactionmessage rptransactionmessage) throws messagebizexception;
	 /** * Send messages directly.
	
	
	*/public void Directsendmessage (Rptransactionmessage rptransactionmessage) throws messagebizexception;
	 /** * Re-send the message.
	
	
	*/public void Resendmessage (Rptransactionmessage rptransactionmessage) throws messagebizexception;
	 /** * Re-sends a message based on MessageID.
	
	
	*/public void Resendmessagebymessageid (String messageId) throws messagebizexception;
	 /** * Flag message as Death message.


	*/public void Setmessagetoareadlydead (String messageId) throws messagebizexception; /** * Get messages based on message ID */public rptransactionmessage Getmessagebymessageid (String messageId) throws Messagebizexception;
	
	
	/** * Delete message based on message ID */public void Deletemessagebymessageid (String messageId) throws messagebizexception;
	 /** * Re-sends all dead messages in a message queue.
	
	*/public void Resendalldeadmessagebyqueuename (String queuename, int batchsize) throws messagebizexception; /** * Get Paging data */Pagebean Listpage (Pageparam pageparam, map<string, object> parammap) throws Messagebizexception


; }
3, Rptransactionmessageserviceimpl
@Service ("Rptransactionmessageservice") public class Rptransactionmessageserviceimpl implements

	Rptransactionmessageservice {private static final log log = Logfactory.getlog (Rptransactionmessageserviceimpl.class);

	@Autowired private Rptransactionmessagedao Rptransactionmessagedao;

	@Autowired private Jmstemplate notifyjmstemplate; public int savemessagewaitingconfirm (Rptransactionmessage message) {if (message = = null) {throw new Messagebizex
		Ception (Messagebizexception.sava_message_is_null, "The saved message is empty"); } if (Stringutil.isempty (Message.getconsumerqueue ())) {throw new Messagebizexception (Messagebizexception.message_co
		Nsumer_queue_is_null, "The consumption queue for messages cannot be empty");
		} message.setedittime (New Date ());
		Message.setstatus (MessageStatusEnum.WAITING_CONFIRM.name ());
		Message.setareadlydead (PublicEnum.NO.name ());
		Message.setmessagesendtimes (0);
	return Rptransactionmessagedao.insert (message); } public void Confirmandsendmessage (String messageId) {final RpTRansactionmessage message = Getmessagebymessageid (messageId);
		if (message = = null) {throw new Messagebizexception (Messagebizexception.sava_message_is_null, "the message found based on the message ID is empty");
		} message.setstatus (MessageStatusEnum.SENDING.name ());
		Message.setedittime (New Date ()); Rptransactionmessagedao

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.