mysql触发器调用python_MySQL触发器到RabbitMQ

那么你就可以这样做了(自述文件中的剪切粘贴):SET @AMQP_URL = 'amqp://guest:guest@localhost:5672';

SET @AMQP_EXCHANGE = 'udf';

DROP TABLE IF EXISTS `accounts`;

CREATE TABLE `accounts` (

`id` int(11) unsigned NOT NULL AUTO_INCREMENT,

`username` varchar(64) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='Customer Accounts';

DELIMITER ;;

DROP TRIGGER IF EXISTS `after_insert_on_accounts`;

CREATE DEFINER=`root`@`localhost` TRIGGER `after_insert_on_accounts` AFTER INSERT ON `accounts` FOR EACH ROW BEGIN

SET @message_id = (SELECT lib_mysqludf_amqp_sendjson(@AMQP_URL, @AMQP_EXCHANGE, 'accounts.insert', json_object('id', NEW.id, 'username', NEW.username)));

END ;;

DROP TRIGGER IF EXISTS `after_update_on_accounts`;

CREATE DEFINER=`root`@`localhost` TRIGGER `after_update_on_accounts` AFTER UPDATE ON `accounts` FOR EACH ROW BEGIN

SET @message_id = (SELECT lib_mysqludf_amqp_sendjson(@AMQP_URL, @AMQP_EXCHANGE, 'accounts.update', json_object('id', NEW.id, 'username', NEW.username)));

END ;;

DROP TRIGGER IF EXISTS `after_delete_on_accounts`;

CREATE DEFINER=`root`@`localhost` TRIGGER `after_delete_on_accounts` AFTER DELETE ON `accounts` FOR EACH ROW BEGIN

SET @message_id = (SELECT lib_mysqludf_amqp_sendjson(@AMQP_URL, @AMQP_EXCHANGE, 'accounts.delete', json_object('id', OLD.id, 'username', OLD.username)));

END ;;

DELIMITER ;

INSERT INTO accounts (username) values ('jdoe');

UPDATE accounts SET username = 'jsmith';

DELETE FROM accounts WHERE id = last_insert_id();

不过,我怀疑它会打开一个到RabbitMQ的新连接,并为每条消息登录,这很可能会产生糟糕的性能。但我不确定。在

你可能感兴趣的:(mysql触发器调用python_MySQL触发器到RabbitMQ)