什么是“交易工作单元"?用简单的英语? [英] What is a "transactional unit of work" in plain english?

查看:110
本文介绍了什么是“交易工作单元"?用简单的英语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该问题直接来自SO中的我之前的问题.我仍然无法理解将JMS会话用作事务性工作单元的概念.

This question follows directly from a previous question of mine in SO. I am still unable to grok the concept of JMS sessions being used as a transactional unit of work .

Java消息服务本书中:

QueueConnection对象用于创建JMS会话对象 (特别是队列会话),它是工作线程, JMS中的事务性工作单元.与JDBC不同,JDBC需要一个 每个事务性工作单元的连接,JMS使用单个 连接和多个Session对象.通常,应用程序将 在应用程序启动时创建单个JMS连接并维护一个 会话对象池,可在需要发送消息时使用 生产或消费.

The QueueConnection object is used to create a JMS Session object (specifically, a Queue Session), which is the working thread and transactional unit of work in JMS. Unlike JDBC, which requires a connection for each transactional unit of work, JMS uses a single connection and multiple Session objects. Typically, applications will create single JMS Connection on application startup and maintain a pool of Session objects for use whenever a message needs to be produced or consumed.

我无法理解事务性工作单位一词的含义.我在这里寻找的是带有示例的简单明了的解释.

I am unable to understand the meaning of the phrase transactional unit of work. A plain and simple explanation with an example is what I am looking for here.

推荐答案

一个工作单元必须完成全部或不完成任何工作.如果无法完成,则一定会从未发生过.

A unit of work is something that must complete all or nothing. If it fails to complete it must be like it never happened.

在JTA中,工作单元由transaction.begin()调用和transaction.commit()调用之间与transactional资源的交互组成.

In JTA parlance a unit of work consists of interactions with a transactional resource between a transaction.begin() call and a transaction.commit() call.

假设您定义一个工作单元,该工作单元提取源队列的消息,在数据库中插入一条记录,然后将另一条消息放入目标队列.在这种情况下,transaction aware资源是两个JMS队列和数据库.

Lets say you define a unit of work that pulls a message of a source queue, inserts a record in a database, and puts the another message on a destination queue. In this scenario transaction aware resources are the two JMS queues and the database.

如果在数据库插入之后发生故障,那么必须发生许多事情才能实现原子性.必须回滚数据库提交,以便您在数据源中没有孤立的记录,并且必须替换从源队列中拉出的消息.

If a failure occurs after the database insert then a number of things must happen to achieve atomicity. The database commit must be rolled back so you don't have an orphaned record in the datasource and the message that was pulled off the source queue must be replaced.

在这种人为情况下的结果是,无论unit of work在哪里发生故障,结果都是您开始时所处的确切状态.

The net out in this contrived scenario is that regardless of where a failure occurs in the unit of work the result is the exact state that you started in.

要记住的有关消息传递系统的关键是,一个更全局的事务可以由几个较小的原子事务交接队列组成.

The key to remember about messaging systems is that a more global transaction can be composed of several smaller atomic transactional handoffs queue to queue.

Queue A -> Processing Agent -> Queue B --> Processing Agent --> Queue C

在这种情况下,实际上并不存在全局事务上下文(例如,将B->C中的故障一直追溯到A),您所要做的就是保证消息将沿着链条传递或保留在其源队列中.这使系统在任何时候都保持一致.可以通过创建错误路由来处理异常状态,以实现更全局的一致性状态.

While in this scenario there isn't really a global transactional context(for instance rolling a failure in B->C all the way back to A) what you do have is garauntees that messages will either be delivered down the chain or remain in their source queues. This makes the system consistent at any instant. Exception states can be handled by creating error routes to achieve a more global state of consistency.

这篇关于什么是“交易工作单元"?用简单的英语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆