简体   繁体   English

使用 AWS Aurora Postgres 和 aws_lambda.invoke 的事务发件箱模式

[英]Transaction Outbox Pattern with AWS Aurora Postgres and aws_lambda.invoke

I am working on a project which is made out of a couple of microservices.我正在开发一个由几个微服务组成的项目。 I am planning to use Transaction Outbox Pattern by calling a lambda function in Postgres after insert trigger.我计划在插入触发器后通过在 Postgres 中调用 lambda function 来使用事务发件箱模式。

I am thinking something like this我在想这样的事情

CREATE OR REPLACE FUNCTION tx_msg_func()    RETURNS trigger AS
$$
DECLARE newRecord JSON;
BEGIN
    newRecord :=  row_to_json(NEW.*);

    PERFORM * FROM aws_lambda.invoke(
        aws_commons.create_lambda_function_arn('my_lambda_function'),
        newRecord,
        'Event'
    );

    RETURN NEW;
END;

$$
LANGUAGE 'plpgsql';

CREATE TRIGGER tx_msg_insert AFTER INSERT ON tx_outbox_table
FOR EACH ROW EXECUTE PROCEDURE tx_msg_func();

Here, the lambda function will receive the new record as JSON and will send an SQS message.在这里,lambda function 将收到新记录 JSON 并将发送 SQS 消息。 After sending the message successfully, it will delete the record from tx_outbox_table消息发送成功后,会从tx_outbox_table中删除记录

I am wondering if there is any downside here that I am missing.我想知道这里是否有我遗漏的缺点。 Do you think this is a production-ready solution?你认为这是一个生产就绪的解决方案吗? Is there anything I should be aware of?有什么我应该注意的吗?

Well, what about transaction?那么,交易呢? It should be as short as possible.它应该尽可能短。 After insert is executed inside transaction, so... TCP call goes inside the transaction.在事务内部执行插入后,所以... TCP 调用进入事务内部。 What can be done with it?可以用它做什么? Here is an idea. 是一个想法。 Exceptions are processed outside current transaction.异常在当前事务之外处理。 New transaction is lighter when nothing is written, so maybe that is the way to go?什么都不写时新事务更轻,所以也许这就是 go 的方式?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM